CF1701F.Points
省选/NOI-
通过率:0%
时间限制:6.50s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A triple of points i, j and k on a coordinate line is called beautiful if i<j<k and k−i≤d.
You are given a set of points on a coordinate line, initially empty. You have to process queries of three types:
- add a point;
- remove a point;
- calculate the number of beautiful triples consisting of points belonging to the set.
在一条坐标轴上,若三点 i、j 和 k 满足 i<j<k 且 k−i≤d,则称该三元组为“优美的”。
给定一个初始为空的坐标轴上的点集。你需要处理三种类型的查询:
- 添加一个点;
- 删除一个点;
- 计算当前点集中构成的优美三元组的个数。
输入格式
The first line contains two integers q and d (1≤q,d≤2⋅105) — the number of queries and the parameter for defining if a triple is beautiful, respectively.
The second line contains q integers a1,a2,…,aq (1≤ai≤2⋅105) denoting the queries. The integer ai denotes the i-th query in the following way:
- if the point ai belongs to the set, remove it; otherwise, add it;
- after adding or removing the point, print the number of beautiful triples.
第一行包含两个整数 q 和 d(1≤q,d≤2⋅105),分别表示查询次数以及用于判断三元组是否“优美”的参数。
第二行包含 q 个整数 a1,a2,…,aq(1≤ai≤2⋅105),表示各次查询。整数 ai 表示第 i 次查询,其含义如下:
- 若点 ai 已在集合中,则将其移除;否则将其加入集合;
- 在完成点的添加或移除操作后,输出当前“优美”三元组的数量。
输出格式
For each query, print one integer — the number of beautiful triples after processing the respective query.
对于每个查询,输出一个整数——即处理相应查询后美丽三元组的数量。
输入输出样例
输入#1
7 5 8 5 3 2 1 5 6
输出#1
0 0 1 2 5 1 5
输入解题思路,AI测评打分。不知道怎么写?