#P11139. [APC001] D - Array Again

[APC001] D - Array Again

Problem Description

You need to maintain a sequence that supports 44 types of operations:

  1. 1 x y: Insert yy numbers xx into the sequence consecutively.
  2. 2 x y: Delete xx from the sequence yy times consecutively. If, in some deletion, xx no longer exists in the sequence, ignore that deletion.
  3. 3: Deduplicate the sequence. That is, for each distinct positive integer xx that has appeared in the sequence, if it appears more than 11 time, keep only one xx in the sequence and delete all the others.
  4. 4 x: Query the number of occurrences of xx in the sequence.

For each operation 4, output the answer.

Input Format

The first line contains an integer qq, which represents the number of operations.

The next qq lines each contain several integers, describing one operation.

Output Format

For each operation 4, output one line containing the answer.

The testdata guarantees that there is at least one operation 4.

5
1 2 10
2 2 5
4 2
3
4 2
5
1
4
1 1000000000 1000000000
1 1000000000 1000000000
1 1000000000 1000000000
4 1000000000
3000000000
20
4 95002957
2 384405322 255642125
2 384405322 174926753
2 384405322 51265222
1 384405322 311383201
4 384405322
1 384405322 5464229
4 22438767
4 17075617
1 384405322 153189933
1 230228188 148299369
1 7168162 387115701
1 384405322 154480360
1 384405322 438458686
3
1 7961090 98996809
4 153074129
1 975025351 171484003
1 384405322 650527951
4 384405322
0
311383201
0
0
0
650527952

Hint

Sample Explanation 11

Operation 11: Insert 1010 copies of 22.

Operation 22: Delete 55 copies of 22. After that, the sequence contains only 55 copies of 22.

Operation 33: Query the number of occurrences of 22, which is 55.

Operation 44: Deduplicate the sequence. After that, the sequence contains only one 22.

Operation 55: Query the number of occurrences of 22, which is 11.

Sample Explanation 22

Please note that the answer may exceed the range of int.

Constraints

For 100%100\% of the testdata, 1q1051 \le q \le 10^5, 1x,y1091 \le x, y \le 10^9.

Please note: Since there is no partial scoring in the contest where this problem comes from, you can get full score only by passing all test points; otherwise, you will get 00 points.

Translated by ChatGPT 5