atcoder#ABC294D. [ABC294D] Bank

[ABC294D] Bank

Score : 400400 points

Problem Statement

NN people, with ID numbers 11, 22, \dots, NN, are lining up in front of a bank. There will be QQ events. The following three kinds of events can happen.

  • 1 : The teller calls the person with the smallest ID number who has not been called.
  • 2 x : The person with the ID number xx comes to the teller for the first time. (Here, person xx has already been called by the teller at least once.)
  • 3 : The teller again calls the person with the smallest ID number who has already been called but has not come.

Print the ID numbers of the people called by the teller in events of the third kind.

Constraints

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • 2Q5×1052 \leq Q \leq 5 \times 10^5
  • There will not be an event of the first kind when all people have already been called at least once.
  • For each event of the second kind, the person with the ID number xx has already been called by the teller at least once.
  • For each event of the second kind, the person with the ID number xx will not come to the teller more than once.
  • There will not be an event of the third kind when all people who have already been called have come to the teller.
  • There is at least one event of the third kind.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format, where eventi\text{event}_i denotes the ii-th event:

NN QQ

event1\text{event}_1

event2\text{event}_2

\vdots

eventQ\text{event}_Q

The description of each event is in one of the following formats:

1

2 xx

3

Output

Print XX lines, where XX is the number of events of the third kind. The ii-th line should contain the ID number of the person called in the ii-th event of the third kind.

4 10
1
1
3
2 1
1
2 3
3
1
2 2
3
1
2
4

For each i=1,2,,Qi = 1, 2, \dots, Q, shown below is the set of people who have already been called but have not come just before the ii-th event.

  • i=1i=1 : {}\lbrace \rbrace
  • i=2i=2 : {1}\lbrace 1\rbrace
  • i=3i=3 : {1,2}\lbrace 1,2\rbrace
  • i=4i=4 : {1,2}\lbrace 1,2\rbrace
  • i=5i=5 : {2}\lbrace 2\rbrace
  • i=6i=6 : {2,3}\lbrace 2,3\rbrace
  • i=7i=7 : {2}\lbrace 2\rbrace
  • i=8i=8 : {2}\lbrace 2\rbrace
  • i=9i=9 : {2,4}\lbrace 2,4\rbrace
  • i=10i=10 : {4}\lbrace 4\rbrace

The events for i=3,7,10i=3,7,10 are of the third kind, so you should print the persons with the smallest ID numbers in the sets for those events: 1,2,41, 2, 4.