CF756C.Nikita and stack

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 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!

尼基塔有一个栈。本题中的栈是一种支持两种操作的数据结构:push(x) 操作将整数 xx 压入栈顶;pop() 操作则删除栈顶的整数(即最后加入的那个)。若栈为空,则 pop() 操作不执行任何操作。

尼基塔曾对这个栈执行了 mm 次操作,但他忘记了这些操作的具体内容。现在他试图逐一回忆起来:在第 ii 步,他回忆起自己当初执行的第 pip_i 个操作。换言之,他按某个排列 p1, p2, …, pmp_1,\,p_2,\,\dots,\,p_m 的顺序回忆这些操作。在每一步之后,尼基塔都想知道:若按他当前已回忆起的操作(按原始时间顺序)依次执行,此时栈顶的整数是多少?请帮助他!

输入格式

The first line contains the integer m (1 ≤ m ≤ 105) — 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 ≤ 106) — the integer added to the stack.

It is guaranteed that each integer from 1 to m is present exactly once among integers p__i.

第一行包含一个整数 mm(1≤m≤1051 \le m \le 10^5)—— Nikita 执行的操作总数。

接下来的 mm 行描述了 Nikita 记得的操作。第 ii 行以两个整数 pip_i 和 tit_i(1≤pi≤m1 \le p_i \le m,ti=0t_i = 0 或 ti=1t_i = 1)开头——分别表示他在第 ii 步所记得的操作的序号及其类型。若 ti=0t_i = 0,则该操作为 pop();若 ti=1t_i = 1,则该操作为 push(x)。若操作为 push(x),该行还包含一个整数 xix_i(1≤xi≤1061 \le x_i \le 10^6)—— 即被压入栈中的整数。

保证整数 11 到 mm 在所有 pip_i 中恰好各出现一次。

输出格式

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.

输出 m 个整数。第 i 个整数应等于 Nikita 在第 1 步至第 i 步执行完所有他记得的操作后,栈顶的数字。如果执行完所有这些操作后栈为空,则输出 -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 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.

在第一个例子中,Nikita 回忆起第一步的操作后,唯一执行的操作是 push(2),因此答案为 2。随后他回忆起在 push(2) 之前执行的 pop() 操作,答案保持不变。

在第二个例子中,操作序列为 push(2)、push(3) 和 pop()。Nikita 按照它们实际执行的顺序回忆这些操作。

在第三个例子中,Nikita 以相反的顺序回忆这些操作。

输入解题思路,AI测评打分。不知道怎么写?

首页