#abc356f. F - Distance Component Size Query

F - Distance Component Size Query

Score : 525525 points

问题陈述

给定一个整数 KK。对于一个最初为空的集合 SS,按顺序处理 QQ 个查询,包括以下两种类型:

  • 1 x:给定一个整数 xx。如果 xxSS 中,则从 SS 中移除 xx。否则,将 xx 添加到 SS
  • 2 x:给定一个在 SS 中的整数 xx。考虑一个图,其中顶点是 SS 中的数字,并且只有当两个数字之间的绝对差值最多为 KK 时,这两个数字之间才有边。打印包含 xx 的连通分量中的顶点数。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given an integer KK. For a set SS that is initially empty, process QQ queries of the following two types in order:

  • 1 x: An integer xx is given. If xx is in SS, remove xx from SS. Otherwise, add xx to SS.
  • 2 x: An integer xx that is in SS is given. Consider a graph where the vertices are the numbers in SS, and there is an edge between two numbers if and only if the absolute difference between them is at most KK. Print the count of vertices in the connected component that contains xx.

Constraints

  • 1Q2×1051 \leq Q \leq 2\times 10^5
  • 0K10180 \leq K \leq 10^{18}
  • For each query, 1x10181 \leq x \leq 10^{18}.
  • For each query of the second type, the given xx is in SS at that point.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

QQ KK

query1\mathrm{query}_1

\vdots

queryQ\mathrm{query}_Q

Each query is given in the following format:

11 xx

22 xx

Output

Process the queries.

Sample Input 1

7 5
1 3
1 10
2 3
1 7
2 3
1 10
2 3

Sample Output 1

1
3
2

The query processing proceeds as follows:

  • In the first query, 33 is added to SS, resulting in S={3}S=\{3\}.
  • In the second query, 1010 is added to SS, resulting in S={3,10}S=\{3,10\}.
  • In the third query, consider a graph with vertices 33 and 1010 and no edges. The connected component containing 33 has a size of 11, so print 11.
  • In the fourth query, 77 is added to SS, resulting in S={3,7,10}S=\{3,7,10\}.
  • In the fifth query, consider a graph with vertices 33, 77, and 1010, with edges between 33 and 77, and 77 and 1010. The connected component containing 33 has a size of 33, so print 33.
  • In the sixth query, 1010 is removed from SS, resulting in S={3,7}S=\{3,7\}.
  • In the seventh query, consider a graph with vertices 33 and 77, with an edge between them. The connected component containing 33 has a size of 22, so print 22.

Sample Input 2

11 1000000000000000000
1 1
1 100
1 10000
1 1000000
1 100000000
1 10000000000
1 1000000000000
1 100000000000000
1 10000000000000000
1 1000000000000000000
2 1

Sample Output 2

10

Sample Input 3

8 0
1 1
1 2
2 1
1 1
1 2
1 1
1 2
2 1

Sample Output 3

1
1