Problem C. YJJ’s Stack
时间限制 5000 ms
内存限制 128 MB
As it’s known to all, there’s a cute girl named YJJ living in Sand River. One day when he was learning stack, he suddenly thought that it would be more interesting to add timestamp to each stack command, and wanted to delete the element(even it’s not the top one) as he wanted.
So he invented a stack called "YJJ's stack", which supports the following four command:
● push v t – push $v$ into YJJ’s stack, whose timestamp is $t$ ;
● delete v t – delete the uppermost element from the stack which is equal to $v$ , whose timestamp is $t$ ;
● pop t – pop the top element from YJJ’s stack, whose timestamp is $t$ ;
● query t – execute a query operation which is described below, whose timestamp is $t$ ;
There is an empty set of commands initially. When an command except query t arrives, we put the command into the set. When an command query t arrives, we process as follows:
1. Clear YJJ's stack .
2. Execute the command currently in the set whose timestamp is less than t .
3. The executing order of command is ordered by their timestamp in ascending order.
4. Print the top element in the stack.
Records of command are in arriving order, you are required to execute according to above rules. Another three constraints are made to simplify the problem :
1. All the pop and delete command are valid. In another word, if you do the process correctly, pop command will not be excuted on an empty YJJ’s stack and delete v command will not be excuted on an YJJ’s stack without v .
2. All timestamps are different.
3. The number of pop command is no more than $5$.
输入数据
输出数据
For each query command, output the answer in a line. If the stack is empty, output $-1$ instead.
样例输入
复制
2
13
push 2 10
push 1 20
query 21
delete 2 30
query 31
push 3 40
query 53
pop 60
query 62
push 2 70
query 41
push 1 50
query 91
9
push 2 10
push 1 20
query 11
query 21
delete 2 30
query 31
query 12
pop 40
query 41
样例输出
复制
1
1
3
1
3
2
2
1
1
2
-1
$ Mathjax font initiator $