#BS0000224. Kích thước thành phần liên thông theo khoảng cách (Distance Component Size Query)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Kích thước thành phần liên thông theo khoảng cách (Distance Component Size Query)
Distance Component Size Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
An initially empty set and a nonnegative integer are given. Each value appears at most once. A type- operation toggles membership of : remove it if present, insert it otherwise.
For a type- operation, form an undirected graph on the current values in . Distinct vertices are adjacent exactly when . Count the vertices reachable from , including itself. Each queried is guaranteed to be present at that time.
Input
The first line gives integers .
Each of the next lines gives integers : type toggles membership and type requests the component size of .
Output
For every type- operation, print the current component size on its own line. Type- operations produce no output.
Subtasks
- Subtask 1 (20 points): ; ; ; ; each type- query has at query time.
- Subtask 2 (30 points): ; ; ; ; each type- query has at query time; each type- operation inserts a value not already in (no removals).
- Subtask 3 (50 points): ; ; ; ; each type- query has at query time.
Examples
Input
8 4
1 2
1 10
2 2
1 6
2 10
1 6
2 10
2 2
Output
1
3
1
1
Explanation
For , the gap separates the vertices. Inserting creates the edges and , connecting all three vertices. Removing destroys these edges; the last two queries each address an isolated vertex.