Silver's strange exam
Time limit3sMemory limit1024 MB
Students enter and leave a lab holding integers, and each strange event awards points to students with unique values; print each entrant's final score.
- Level
Hard8 of 10
- Topics
- Segment tree, Implementation, Simulation
- Solved
- No attempts yet
Problem
Silver is the teaching assistant for a university course and likes guessing games. To keep students enjoying the lab, Silver decided to score their lab points in a strange way.
Each student may enter and leave the lab freely, but once a student leaves, they cannot come back. When entering, a student writes an integer from to on a sheet of paper and brings it in. During the lab, Silver opens a strange event. When the event opens, each student currently in the lab scores as follows.
- If the integer they wrote is the same as another person's integer in the lab, they score nothing.
- If the integer they wrote is different from every other person's integer in the lab, they score point.
- Among the students whose integers are unique in the lab, the one who wrote the largest number gets extra points, for a total of . The value of may differ for each event. If no student has a unique integer, nobody scores extra.
Silver recorded the entries, exits, and strange events as queries. Each query has one of the following forms.
- : A student holding the integer enters the lab.
- : The student who was the -th to enter overall leaves the lab. The count includes students who left earlier. The -th student is in the lab at this moment.
- : A strange event opens. Each student in the lab whose integer is unique in the lab gets point. The student with the largest such integer gets more points.
After processing all queries in order, write a program that outputs the scores of the 1st through -th students to enter, in order, where is the number of type queries.
Input
The first line contains the number of queries . ()
Each of the next lines contains one query, which is , , or .
- There is at least one type query.
- For a type query, and is an integer.
- For a type query, and is an integer. The -th student to enter is in the lab.
- For a type query, and is an integer.
Output
Print lines, where is the number of type queries.
On the -th line, print the score of the -th student to enter.