#FT0000137. Máy thời gian của Artem (Little Artem and Time Machine)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Máy thời gian của Artem (Little Artem and Time Machine)
Little Artem and Time Machine
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Artem maintains an integer multiset, meaning that the same integer may have several copies. With a time machine, he can apply changes at arbitrary moments in time. Each input operation has a type , a time , and a value :
1 t x: insert one copy of at time .2 t x: remove exactly one copy of at time .3 t x: ask how many copies of exist at time , considering only modifications that have appeared earlier in input order.
Times need not be increasing in the input. A modification at time affects every moment from onward. An answer to a query is never retroactively modified by a change appearing later in the input, even if that change targets an earlier time.
All input times are pairwise distinct. Removal operations are guaranteed valid: after each modification, the history constructed so far contains a nonnegative number of copies of every value at every moment. Count only the copies present at the requested moment; do not print the whole multiset.
Input
The first line contains , the number of operations. Each of the following lines contains three integers in execution order.
Output
For each type-3 operation, print one line containing the number of copies of at time according to the history known when that query is issued. Print nothing for insertions and removals.
Subtasks
- Subtask 1 (20 points): ; ; ; all times are pairwise distinct; every removal is valid after each modification.
- Subtask 2 (30 points): ; ; ; all times are pairwise distinct; every removal is valid after each modification.
- Subtask 3 (50 points): ; ; ; all times are pairwise distinct; every removal is valid after each modification.
Examples
Example 1
Input
6
1 1 5
3 5 5
1 2 5
3 6 5
2 3 5
3 7 5
Output
1
2
1
Explanation
- After
1 1 5, one copy of exists from time onward, so the first query3 5 5prints 1. - The insertion
1 2 5creates a second copy starting at time . Query3 6 5therefore prints 2. - The deletion
2 3 5then removes one copy from time onward. The last query at time prints 1. The earlier answer 2 is not changed.
Example 2
Input
3
1 1 1
2 2 1
3 3 1
Output
0
Explanation
is inserted at and removed at . At no copy remains, so the answer is 0.