PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000137. Máy thời gian của Artem (Little Artem and Time Machine)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 aa, a time tt, and a value xx:

  • 1 t x: insert one copy of xx at time tt.
  • 2 t x: remove exactly one copy of xx at time tt.
  • 3 t x: ask how many copies of xx exist at time tt, considering only modifications that have appeared earlier in input order.

Times tt need not be increasing in the input. A modification at time tt affects every moment from tt 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 nn, the number of operations. Each of the following nn lines contains three integers ai,ti,xia_i,t_i,x_i in execution order.

Output

For each type-3 operation, print one line containing the number of copies of xx at time tt according to the history known when that query is issued. Print nothing for insertions and removals.

Subtasks

  • Subtask 1 (20 points): 1≤n≤801\le n\le 80; 1≤ai≤31\le a_i\le 3; 1≤ti,xi≤1091\le t_i,x_i\le 10^9; all times tit_i are pairwise distinct; every removal is valid after each modification.
  • Subtask 2 (30 points): 1≤n≤40001\le n\le 4000; 1≤ai≤31\le a_i\le 3; 1≤ti,xi≤1091\le t_i,x_i\le 10^9; all times tit_i are pairwise distinct; every removal is valid after each modification.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ai≤31\le a_i\le 3; 1≤ti,xi≤1091\le t_i,x_i\le 10^9; all times tit_i 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 55 exists from time 11 onward, so the first query 3 5 5 prints 1.
  • The insertion 1 2 5 creates a second copy starting at time 22. Query 3 6 5 therefore prints 2.
  • The deletion 2 3 5 then removes one copy from time 33 onward. The last query at time 77 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

11 is inserted at t=1t=1 and removed at t=2t=2. At t=3t=3 no copy remains, so the answer is 0.