CF756C.Nikita and stack

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer xx 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 mm operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the ii -th step he remembers an operation he made pip_{i} -th. In other words, he remembers the operations in order of some permutation p1,p2,...,pmp_{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!

输入格式

The first line contains the integer mm ( 1<=m<=1051<=m<=10^{5} ) — the number of operations Nikita made.

The next mm lines contain the operations Nikita remembers. The ii -th line starts with two integers pip_{i} and tit_{i} ( 1<=pi<=m1<=p_{i}<=m , ti=0t_{i}=0 or ti=1t_{i}=1 ) — the index of operation he remembers on the step ii , and the type of the operation. tit_{i} equals 00 , if the operation is pop(), and 11 , is the operation is push(x). If the operation is push(x), the line also contains the integer xix_{i} ( 1<=xi<=1061<=x_{i}<=10^{6} ) — the integer added to the stack.

It is guaranteed that each integer from 11 to mm is present exactly once among integers pip_{i} .

输出格式

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

输入输出样例

  • 输入#1

    2
    2 1 2
    1 0
    

    输出#1

    2
    2
    
  • 输入#2

    3
    1 1 2
    2 1 3
    3 0
    

    输出#2

    2
    3
    2
    
  • 输入#3

    5
    5 0
    4 0
    3 1 1
    2 1 1
    1 1 2
    

    输出#3

    -1
    -1
    -1
    -1
    2
    

说明/提示

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 22 . 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.

首页