数据结构与算法专题题库

1007. Max Element

单点时限: 1.0 sec

内存限制: 512 MB

You have an empty sequence, and you will be given N queries. Each query is one of these three types:

1 x -Push the element x into the stack.
2 -Delete the element present at the top of the stack.
3 -Print the maximum element in the stack.

输入格式

The first line of input contains an integer, $N$. The next $N$ lines each contain an above mentioned query. (It is guaranteed that each query is valid.)
$1 \leq N \leq 10^6$
$1 \leq x \leq 10^9 $
$1 \leq type \leq 3 $

输出格式

For each type 3 query, print the maximum element in the stack on a new line.

样例

Input
10
1 97
2
1 20
2
1 26
1 20
2
3
1 91
3
Output
26
91

提示

对于所有操作复杂度要求$O(1)$或者$O(log(N))$

不限期开放

题目列表