A10329 | Little Artem and Time Machine
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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 $a_{i}$ , $t_{i}$ and $x_{i}$ ( $1<=a_{i}<=3$ , $1<=t_{i},x_{i}<=10^{9}$ ) — 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.
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}<=10^{9}$ ) — 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.
输出格式
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted