The God of Death is a famous assassin. As his student, you are assigned to keep track of targets, numbered . The God of Death will then give you queries.
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 integers, , the locations of the targets on day 0.
The next line will contain .
The next lines will each contain a valid query, as described above.
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
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
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.