Under construction

Still being built. Things may change

Silver's strange exam

Time limit3sMemory limit1024 MB

Summary
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 11 to 1 000 0001\,000\,000 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 11 point.
  • Among the students whose integers are unique in the lab, the one who wrote the largest number gets ss extra points, for a total of 1+s1+s. The value of ss may differ for each event. If no student has a unique integer, nobody scores extra.

Silver recorded the entries, exits, and strange events as QQ queries. Each query has one of the following forms.

  • 1 x1\ x: A student holding the integer xx enters the lab.
  • 2 k2\ k: The student who was the kk-th to enter overall leaves the lab. The count includes students who left earlier. The kk-th student is in the lab at this moment.
  • 3 s3\ s: A strange event opens. Each student in the lab whose integer is unique in the lab gets 11 point. The student with the largest such integer gets ss more points.

After processing all queries in order, write a program that outputs the scores of the 1st through NN-th students to enter, in order, where NN is the number of type 11 queries.

Input

The first line contains the number of queries QQ. (1≤Q≤500 0001\le Q\le 500\,000)

Each of the next QQ lines contains one query, which is 1 x1\ x, 2 k2\ k, or 3 s3\ s.

  • There is at least one type 11 query.
  • For a type 11 query, 1≤x≤1 000 0001\le x\le 1\,000\,000 and xx is an integer.
  • For a type 22 query, 1≤k1\le k and kk is an integer. The kk-th student to enter is in the lab.
  • For a type 33 query, 1≤s≤1091\le s\le 10^9 and ss is an integer.

Output

Print NN lines, where NN is the number of type 11 queries.

On the ii-th line, print the score of the ii-th student to enter.

Examples1

  1. Example 1

    Input
    18
    1 3
    3 100
    1 7
    3 200
    1 5
    3 400
    1 7
    3 800
    2 2
    3 1600
    1 5
    3 3200
    1 7
    3 6400
    1 3
    3 12800
    2 5
    3 25600
    
    Expected output
    6507
    602
    26404
    4802
    0
    0
    0