题库练习 Rollbacks (Easy Version)
← 上一题 下一题 →

A16117 | Rollbacks (Easy Version)

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

This is an easy version of this problem. The only difference between the versions is that you have to solve the hard version in online mode. You can make hacks only if both versions of the problem are solved.

You have an array $a$ , which is initially empty. You need to process queries of the following types:

- + $x$ — add the integer $x$ to the end of the array $a$ .
- - $k$ — remove the last $k$ numbers from the array $a$ .
- ! — roll back the last active change (i.e., make the array $a$ the way it was before the change). In this problem, only queries of the first two types (+ and -) are considered as changes.
- ? — find the number of distinct numbers in the array $a$ .

输入格式

The first line contains an integer $q$ ( $1 \leq q \leq 10^6$ ) — the number of queries.

The next $q$ lines contain the queries as described above.

It is guaranteed that

- in the queries of the first type, $1 \le x \le 10^6$ ;
- in the queries of the second type, $k \ge 1$ and $k$ does not exceed the current length of the array $a$ ;
- at the moment of the queries of the third type, there is at least one query of the first or of the second type that can be rolled back.

It is also guaranteed that the number of queries of the fourth type (?) does not exceed $10^5$ .

输出格式

For each query of the fourth type output one integer — the number of distinct elements in array $a$ at the moment of query.

输入输出样例

输入 #1
10
+ 1
+ 2
+ 2
?
!
+ 3
- 2
?
+ 1
?
输出 #1
2
1
1
输入 #2
6
+ 1
+ 1000000
?
!
!
?
输出 #2
2
0
C++ 编辑器
输入
输出