#P9867. [POI 2021/2022 R2] kon
[POI 2021/2022 R2] kon
Background
Translated from POI2021~2022R2 Day2T2。
Problem Description
There is a dance party. At the beginning, there are only persons and , and both of them are willing to dance with each other.
Then there are events, corresponding to the following operations:
W x: A new person joins. They and person are mutually willing to dance with each other.Z x: A new person joins. Initially, they are mutually willing to dance with everyone that person is willing to dance with.? x: Query how many people are willing to dance with .
The new person’s index is the current number of people plus one.
Input Format
The first line contains an integer .
Then follow lines. Each line contains a character and an integer , with the meaning as described above.
Output Format
For each ? operation, output one line with the answer.
7
? 1
Z 2
? 1
Z 1
W 2
? 2
? 3
1
2
3
2
Hint
Sample explanation:

Subtasks:
| Subtask ID | Special property | Score |
|---|---|---|
Only operations Z and ? |
||
? always appears in the final part of the operations |
||
| No additional constraints |
Translated by ChatGPT 5