atcoder#ABC279F. [ABC279F] BOX
[ABC279F] BOX
Score : points
Problem Statement
There are boxes numbered , and balls numbered . Initially, box contains just ball .
Process a total of operations that will be performed.
There are three types of operations: , , and .
Type : Put all contents of box into box . It is guaranteed that .
1 X Y
Type : Put ball into box , where is the current total number of balls contained in the boxes.
2 X
Type : Report the number of the box that contains ball .
3 X
Constraints
- All values in the input are integers.
- For each type- operation, and .
- For each type- operation, .
- For each type- operation, ball is contained in some box at that point.
- There is at least one type- operation.
Input
The input is given from Standard Input in the following format. Here, represents the -th operation.
Output
For each type- operation, print a line containing the response as an integer.
5 10
3 5
1 1 4
2 1
2 4
3 7
1 3 1
3 4
1 1 4
3 7
3 6
5
4
3
1
3
This input contains ten operations.
- The first operation is of type . Ball is in box .
- The second operation is of type . Put all contents of box into box .- Box now contains balls and , and box is now empty.
- Box now contains balls and , and box is now empty.
- The third operation is of type . Put ball into box .
- The fourth operation is of type . Put ball into box .
- The fifth operation is of type . Ball is in box .
- The sixth operation is of type . Put all contents of box into box .- Box now contains balls , , , and , and box is now empty.
- Box now contains balls , , , and , and box is now empty.
- The seventh operation is of type . Ball is in box .
- The eighth operation is of type . Put all contents of box into box .- Box now contains ball , and box is now empty.
- Box now contains ball , and box is now empty.
- The ninth operation is of type . Ball is in box .
- The tenth operation is of type . Ball is in box .