Codeforces Round 393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)
E
Nikita and stack
Codeforces
未评级
原题
← DF →
翻译中…

Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer $*x*$ on the top of the stack, and operation pop() deletes the top integer from the stack, i. e. the last added. If the stack is empty, then the operation pop() does nothing.

翻译中…

Nikita made $*m*$ operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the $*i*$-th step he remembers an operation he made $*p*_{*i*}$-th. In other words, he remembers the operations in order of some permutation $*p*_{1}, *p*_{2}, ..., *p*_{*m*}$. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!

翻译中…

Input

翻译中…

The first line contains the integer $*m*$ ($1 ≤ *m* ≤ 10^{5}$) — the number of operations Nikita made.

翻译中…

The next $*m*$ lines contain the operations Nikita remembers. The $*i*$-th line starts with two integers $*p*_{*i*}$ and $*t*_{*i*}$ ($1 ≤ *p*_{*i*} ≤ *m*$, $*t*_{*i*} = 0$ or $*t*_{*i*} = 1$) — the index of operation he remembers on the step $*i*$, and the type of the operation. $*t*_{*i*}$ equals $0$, if the operation is pop(), and $1$, is the operation is push(x). If the operation is push(x), the line also contains the integer $*x*_{*i*}$ ($1 ≤ *x*_{*i*} ≤ 10^{6}$) — the integer added to the stack.

翻译中…

It is guaranteed that each integer from $1$ to $*m*$ is present exactly once among integers $*p*_{*i*}$.

翻译中…

Output

翻译中…

Print $*m*$ integers. The integer $*i*$ should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from $1$ to $*i*$. If the stack is empty after performing all these operations, print -1.

翻译中…

Note

翻译中…

In the first example, after Nikita remembers the operation on the first step, the operation push(2) is the only operation, so the answer is $2$. After he remembers the operation pop() which was done before push(2), answer stays the same.

翻译中…

In the second example, the operations are push(2), push(3) and pop(). Nikita remembers them in the order they were performed.

翻译中…

In the third example Nikita remembers the operations in the reversed order.

翻译中…

样例

Input #1
2
2 1 2
1 0
Output #1
2
2
InputCopy OutputCopy
Input #2
3
1 1 2
2 1 3
3 0
Output #2
2
3
2
InputCopy OutputCopy
Input #3
5
5 0
4 0
3 1 1
2 1 1
1 1 2
Output #3
-1
-1
-1
-1
2
InputCopy OutputCopy
题目信息
题号
760E
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。