QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#9588. Multiset

统计

Consider a multiset $S$ that is initially empty. We will perform $n$ operations sequentially.

In each operation, we add or remove a specific integer $x$ from the multiset $S$. It is guaranteed that at any time, the sum of all elements in the multiset $S$ will not exceed $5 \times 10^5$.

Your task is to calculate and output the number of distinct integers that can be formed by the sum of a subset of elements in $S$ (where each element can either be included or not included in the sum) after each operation.

Please note that the effect of each operation on $S$ is permanent.

Input

The first line contains an integer $n$ ($1 \le n \le 5 \times 10^3$), representing the number of operations.

The next $n$ lines each contain two integers $op$ and $x$ ($op \in \{1, 2\}$, $1 \le x \le 5 \times 10^5$), representing the operation type and the element:

  • If $op = 1$, insert $x$ into $S$. It is guaranteed that $x$ is not already in $S$.
  • If $op = 2$, remove $x$ from $S$. It is guaranteed that $x$ is already in $S$.

It is guaranteed that after each operation, the sum of all elements in $S$ is less than or equal to $5 \times 10^5$.

Output

There are $n$ lines, each containing one integer, where the $i$-th line outputs the number of distinct integers that can be formed by the sum of a subset of $S$ after the $i$-th operation.

Examples

Input 1

4
1 100
1 999
1 10
2 100

Output 1

1
3
7
3

Input 2

7
1 1
1 2
1 1
1 4
1 5
2 1
2 4

Output 2

1
3
4
8
13
12
7

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.