CF641E.Little Artem and Time Machine
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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:
- Add integer to the multiset. Note that the difference between set and multiset is that multiset may store several instances of one integer.
- 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.
- 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.
小 Artem 发明了一台时间机器!他可以前往任意时刻,但他的所有想法当然都集中在计算机科学上。他想将这台时间机器应用于一种著名的数据结构:多重集(multiset)。
Artem 想要构建一个基础的整数多重集。他希望该数据结构支持以下三种操作:
- 向多重集中添加一个整数。注意,集合(set)与多重集(multiset)的区别在于:多重集可以存储同一个整数的多个实例。
- 从多重集中删除一个整数。仅删除该整数的一个实例。Artem 不想处理任何异常情况,因此他假定:每次调用删除操作时,该整数必定存在于多重集中。
- 统计给定整数在多重集中当前存储的实例个数。
那么,时间机器的作用是什么呢?Artem 并非按顺序逐个对多重集执行操作,而是穿梭于不同时刻,并在那些时刻执行对应的操作。考虑如下示例:
- 首先,Artem 在第 1 个时刻向多重集中添加整数 5。
- 接着,Artem 在第 5 个时刻向多重集中添加整数 3。
- 然后,Artem 在第 6 个时刻查询多重集中整数 5 的个数。答案为 1。
- 接着,Artem 回溯到过去,在第 4 个时刻查询多重集中整数 3 的个数。由于 3 是在第 5 个时刻才被加入的,因此在第 4 个时刻,整数 3 的个数为 0。
- 然后,Artem 再次回溯到过去,在第 3 个时刻从多重集中删除整数 5。
- 最后,Artem 在第 7 个时刻查询多重集中整数 5 的个数。结果为 0,因为我们在第 3 个时刻已将 5 删除。
注意:Artem 极其厌恶异常,因此他保证:在每次修改之后,所有删除操作所针对的元素均一定存在于多重集中。第三类查询操作的结果,是在 Artem 执行该查询的那个时刻即时计算得出的,且完全不受他后续所做任何修改的影响。
请帮助 Artem 实现这个“时空旅行者多重集”。
输入格式
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of Artem's queries.
Then follow n lines with queries descriptions. Each of them contains three integers a__i, t__i and x__i (1 ≤ a__i ≤ 3, 1 ≤ t__i, x__i ≤ 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.
输入的第一行包含一个整数 n(1 ≤ n ≤ 100000)—— 表示 Artem 的查询次数。
接下来有 n 行,每行描述一个查询。每行包含三个整数 ai、ti 和 xi(1 ≤ ai ≤ 3,1 ≤ ti,xi ≤ 109),分别表示查询的类型、Artem 为执行该查询所穿越到的时间点,以及该查询本身的值。保证所有时间点互不相同,且在每次操作执行后,所有类型 1 和类型 2 的操作均保持一致。
输出格式
For each ask operation output the number of instances of integer being queried at the given moment of time.
对于每个查询操作,输出在给定时刻所查询整数的出现次数。
输入输出样例
输入#1
6 1 1 5 3 5 5 1 2 5 3 6 5 2 3 5 3 7 5
输出#1
1 2 1
输入#2
3 1 1 1 2 2 1 3 3 1
输出#2
0
输入解题思路,AI测评打分。不知道怎么写?