#abc356f. F - Distance Component Size Query
F - Distance Component Size Query
Score : points
问题陈述
给定一个整数 。对于一个最初为空的集合 ,按顺序处理 个查询,包括以下两种类型:
1 x
:给定一个整数 。如果 在 中,则从 中移除 。否则,将 添加到 。2 x
:给定一个在 中的整数 。考虑一个图,其中顶点是 中的数字,并且只有当两个数字之间的绝对差值最多为 时,这两个数字之间才有边。打印包含 的连通分量中的顶点数。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given an integer . For a set that is initially empty, process queries of the following two types in order:
1 x
: An integer is given. If is in , remove from . Otherwise, add to .2 x
: An integer that is in is given. Consider a graph where the vertices are the numbers in , and there is an edge between two numbers if and only if the absolute difference between them is at most . Print the count of vertices in the connected component that contains .
Constraints
- For each query, .
- For each query of the second type, the given is in at that point.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Each query is given in the following format:
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, is added to , resulting in .
- In the second query, is added to , resulting in .
- In the third query, consider a graph with vertices and and no edges. The connected component containing has a size of , so print .
- In the fourth query, is added to , resulting in .
- In the fifth query, consider a graph with vertices , , and , with edges between and , and and . The connected component containing has a size of , so print .
- In the sixth query, is removed from , resulting in .
- In the seventh query, consider a graph with vertices and , with an edge between them. The connected component containing has a size of , so print .
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