4829: 小阿尔提姆和时间机器

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:3 通过:3

题目描述



E. Little Artem and Time Machine
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multiset of integers. He wants these structure to support operations of three types:
  1. Add integer to the multiset. Note that the difference between set and multiset is that multiset may store several instances of one integer.
  2. Remove integer from the multiset. Only one instance of this integer is removed. Artem doesn't want to handle any exceptions, so he assumes that every time remove operation is called, that integer is presented in the multiset.
  3. Count the number of instances of the given integer that are stored in the multiset.
But what about time machine? Artem doesn't simply apply operations to the multiset one by one, he now travels to different moments of time and apply his operation there. Consider the following example.
  • First Artem adds integer 5 to the multiset at the 1-st moment of time.
  • Then Artem adds integer 3 to the multiset at the moment 5.
  • Then Artem asks how many 5 are there in the multiset at moment 6. The answer is 1.
  • Then Artem returns back in time and asks how many integers 3 are there in the set at moment 4. Since 3 was added only at moment 5, the number of integers 3 at moment 4 equals to 0.
  • Then Artem goes back in time again and removes 5 from the multiset at moment 3.
  • Finally Artyom asks at moment 7 how many integers 5 are there in the set. The result is 0, since we have removed 5 at the moment 3.
Note that Artem dislikes exceptions so much that he assures that after each change he makes all delete operations are applied only to element that is present in the multiset. The answer to the query of the third type is computed at the moment Artem makes the corresponding query and are not affected in any way by future changes he makes.
Help Artem implement time travellers multiset.
Input
The first line of the input contains a single integer n (1≤n≤100000)− the number of Artem's queries.
Then follow n lines with queries descriptions. Each of them contains three integers ai, ti and xi (1≤ai≤3, 1≤ti,xi≤109)− type of the query, moment of time Artem travels to in order to execute this query and the value of the query itself, respectively. It's guaranteed that all moments of time are distinct and that after each operation is applied all operations of the first and second types are consistent.
Output
For each ask operation output the number of instances of integer being queried at the given moment of time.


小阿尔提姆发明了时间机器!他可以去任何地方,但他所有的想法当然都与计算机科学有关。他想把这个时间机器应用到一个著名的数据结构:多集(multiset)。
Artem想要创建一个基本的整数多集。他希望这些结构能够支持三种类型的操作:



将整数添加到多集。注意,set和multiset之间的区别是multiset可以存储一个整数的多个实例。

从多集中移除整数。只删除该整数的一个实例。Artem不想处理任何异常,所以他假设每次调用remove操作时,该整数都会在multiset中显示。

计算存储在多集中的给定整数的实例数。

但是时间机器呢?Artem并不是简单地一个接一个地对多重集应用操作,他现在穿越到不同的时间点,并在那里应用他的操作。考虑下面的例子。



第一个Artem在时间的第1个时刻将整数5添加到多集。

然后Artem将整数3添加到时刻5的多集。

然后Artem问在第6时刻多集中有多少个5。答案是1。

然后Artem回到时间点,问在时刻4时集合中有多少个整数。因为3只在第5时刻被添加,所以第4时刻的整数数等于0。

然后Artem再次回到过去,在第3时刻从多集中移除5。

最后Artyom在时刻7问集合中有多少个整数5。结果是0,因为我们在3处移除了5。

请注意,Artem非常不喜欢异常,以至于他确保在每次更改后,所有删除操作都只应用于multiset中存在的元素。第三类查询的答案是在Artem进行相应查询时计算出来的,并且不受他将来所做更改的任何影响。



帮助Artem实现时间旅行者多集。

Examples
Input
6
1 1 5
3 5 5
1 2 5
3 6 5
2 3 5
3 7 5
Output
1
2
1
Input
3
1 1 1
2 2 1
3 3 1
Output
0




输入格式

输出格式

输入样例 复制

6
1 1 5
3 5 5
1 2 5
3 6 5
2 3 5
3 7 5

输出样例 复制

1
2
1

数据范围与提示