当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6388:YJJ’s Stack

题目描述
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$.
输入解释
The first line of the input contains an integer $T$ $(1≤T≤10)$,which is the number of test cases.

In each case, the first line of the input contains an integer $N$ $(1≤N≤1.2\times 10^5)$. The following $N$ lines each contain an command in one of the following four formats: push v t , delete v t , pop t , query t , where $1≤v≤5, 0≤t≤10^9$, and $v, t$ are integers. The command are given in the order in which they arrive.
输出解释
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
来自杭电HDUOJ的附加信息
Recommend chendu

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6388

最后修改于 2020-10-25T23:30:54+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
10000/5000MS(Java/Others) 131072/131072K(Java/Others)