CF1701F.Points

省选/NOI-

通过率:0%

时间限制:6.50s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A triple of points ii, jj and kk on a coordinate line is called beautiful if i<j<ki \lt j \lt k and k−i≤dk - i \le 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.

在一条坐标轴上,若三点 ii、jj 和 kk 满足 i<j<ki \lt j \lt k 且 k−i≤dk - i \le d,则称该三元组为“优美的”。

给定一个初始为空的坐标轴上的点集。你需要处理三种类型的查询:

  • 添加一个点;
  • 删除一个点;
  • 计算当前点集中构成的优美三元组的个数。

输入格式

The first line contains two integers qq and dd (1≤q,d≤2⋅1051 \le q, d \le 2 \cdot 10^5) — the number of queries and the parameter for defining if a triple is beautiful, respectively.

The second line contains qq integers a1,a2,…,aqa_1, a_2, \dots, a_q (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5) denoting the queries. The integer aia_i denotes the ii-th query in the following way:

  • if the point aia_i belongs to the set, remove it; otherwise, add it;
  • after adding or removing the point, print the number of beautiful triples.

第一行包含两个整数 qq 和 dd(1≤q,d≤2⋅1051 \le q, d \le 2 \cdot 10^5),分别表示查询次数以及用于判断三元组是否“优美”的参数。

第二行包含 qq 个整数 a1,a2,…,aqa_1, a_2, \dots, a_q(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5),表示各次查询。整数 aia_i 表示第 ii 次查询,其含义如下:

  • 若点 aia_i 已在集合中,则将其移除;否则将其加入集合;
  • 在完成点的添加或移除操作后,输出当前“优美”三元组的数量。

输出格式

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测评打分。不知道怎么写?

首页