The God of Death is a famous assassin. As his student, you are assigned to keep track of
C x y
: The -th target moves to location . This action marks the beginning of a new day.Q x y
: Return the location of the -th target on the -th day. It is guaranteed that if it is currently day , .
Can you answer the God of Death's queries?
Input Specification
The first line will contain
The next line will contain
The next line will contain
The next
Output Specification
Output the answer to each Q
query on a new line.
Constraints
For all subtasks:
Subtask 1 [30%]
Subtask 2 [70%]
Sample Input
Copy
3
2 3 1
6
C 3 2
C 2 1
Q 1 1
Q 2 2
C 1 3
Q 3 3
Sample Output
Copy
2
1
2
Comments
For some reason, my
algorithm TLEs on all cases, and my 
algorithm TLEs on subtask 2, both are written in Java. Is this supposed to happen?
Use pairs. If you're using java, make a class for pairs, it's very easy.