#P11139. Maintaining a Sequence
Maintaining a Sequence
Maintaining a Sequence
You are given an initially empty sequence and you need to support 4 types of operations:
- 1 x y: Insert y copies of the number x consecutively into the sequence.
- 2 x y: Delete y occurrences of the number x from the sequence consecutively. If at any deletion x does not exist in the sequence, ignore that deletion.
- 3: Deduplicate the sequence. For every distinct positive integer x that appears in the sequence, if it appears more than once, only one copy of x is retained and all other copies are removed. In mathematical terms, if the frequency \( f(x) > 1 \), then set \( f(x) = 1 \).
- 4 x: Query the number of occurrences of x in the sequence.
For each operation of type 4, output the answer on a new line.
inputFormat
The first line contains an integer n representing the number of operations. The following n lines each represent an operation in one of the following forms:
1 x y
2 x y
3
4 x
It is guaranteed that all numbers are positive integers.
outputFormat
For each operation of type 4, print a single integer which is the count of x in the sequence.
sample
5
1 5 3
4 5
2 5 2
4 5
3
3
1
</p>