A11496 | Jamie and To-do List
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Why I have to finish so many assignments???
Jamie is getting very busy with his school life. He starts to forget the assignments that he has to do. He decided to write the things down on a to-do list. He assigns a value priority for each of his assignment (lower value means more important) so he can decide which he needs to spend more time on.
After a few days, Jamie finds out the list is too large that he can't even manage the list by himself! As you are a good friend of Jamie, help him write a program to support the following operations on the to-do list:
- $set\ a_{i}\ x_{i}$ — Add assignment $a_{i}$ to the to-do list if it is not present, and set its priority to $x_{i}$ . If assignment $a_{i}$ is already in the to-do list, its priority is changed to $x_{i}$ .
- $remove\ a_{i}$ — Remove assignment $a_{i}$ from the to-do list if it is present in it.
- $query\ a_{i}$ — Output the number of assignments that are more important (have a smaller priority value) than assignment $a_{i}$ , so Jamie can decide a better schedule. Output $-1$ if $a_{i}$ is not in the to-do list.
- $undo\ d_{i}$ — Undo all changes that have been made in the previous $d_{i}$ days (not including the day of this operation)
At day $0$ , the to-do list is empty. In each of the following $q$ days, Jamie will do exactly one out of the four operations. If the operation is a $query$ , you should output the result of the query before proceeding to the next day, or poor Jamie cannot make appropriate decisions.
Jamie is getting very busy with his school life. He starts to forget the assignments that he has to do. He decided to write the things down on a to-do list. He assigns a value priority for each of his assignment (lower value means more important) so he can decide which he needs to spend more time on.
After a few days, Jamie finds out the list is too large that he can't even manage the list by himself! As you are a good friend of Jamie, help him write a program to support the following operations on the to-do list:
- $set\ a_{i}\ x_{i}$ — Add assignment $a_{i}$ to the to-do list if it is not present, and set its priority to $x_{i}$ . If assignment $a_{i}$ is already in the to-do list, its priority is changed to $x_{i}$ .
- $remove\ a_{i}$ — Remove assignment $a_{i}$ from the to-do list if it is present in it.
- $query\ a_{i}$ — Output the number of assignments that are more important (have a smaller priority value) than assignment $a_{i}$ , so Jamie can decide a better schedule. Output $-1$ if $a_{i}$ is not in the to-do list.
- $undo\ d_{i}$ — Undo all changes that have been made in the previous $d_{i}$ days (not including the day of this operation)
At day $0$ , the to-do list is empty. In each of the following $q$ days, Jamie will do exactly one out of the four operations. If the operation is a $query$ , you should output the result of the query before proceeding to the next day, or poor Jamie cannot make appropriate decisions.
输入格式
The first line consists of a single integer $q$ $(1<=q<=10^{5})$ — the number of operations.
The following $q$ lines consists of the description of the operations. The $i$ -th line consists of the operation that Jamie has done in the $i$ -th day. The query has the following format:
The first word in the line indicates the type of operation. It must be one of the following four: set, remove, query, undo.
- If it is a set operation, a string $a_{i}$ and an integer $x_{i}$ follows $(1<=x_{i}<=10^{9})$ . $a_{i}$ is the assignment that need to be set to priority $x_{i}$ .
- If it is a remove operation, a string $a_{i}$ follows. $a_{i}$ is the assignment that need to be removed.
- If it is a query operation, a string $a_{i}$ follows. $a_{i}$ is the assignment that needs to be queried.
- If it is a undo operation, an integer $d_{i}$ follows $(0<=d_{i}<i)$ . $d_{i}$ is the number of days that changes needed to be undone.
All assignment names $a_{i}$ only consists of lowercase English letters and have a length $1<=|a_{i}|<=15$ .
It is guaranteed that the last operation is a query operation.
The following $q$ lines consists of the description of the operations. The $i$ -th line consists of the operation that Jamie has done in the $i$ -th day. The query has the following format:
The first word in the line indicates the type of operation. It must be one of the following four: set, remove, query, undo.
- If it is a set operation, a string $a_{i}$ and an integer $x_{i}$ follows $(1<=x_{i}<=10^{9})$ . $a_{i}$ is the assignment that need to be set to priority $x_{i}$ .
- If it is a remove operation, a string $a_{i}$ follows. $a_{i}$ is the assignment that need to be removed.
- If it is a query operation, a string $a_{i}$ follows. $a_{i}$ is the assignment that needs to be queried.
- If it is a undo operation, an integer $d_{i}$ follows $(0<=d_{i}<i)$ . $d_{i}$ is the number of days that changes needed to be undone.
All assignment names $a_{i}$ only consists of lowercase English letters and have a length $1<=|a_{i}|<=15$ .
It is guaranteed that the last operation is a query operation.
输出格式
For each query operation, output a single integer — the number of assignments that have a priority lower than assignment $a_{i}$ , or $-1$ if $a_{i}$ is not in the to-do list.
Interaction
If the operation is a $query$ , you should output the result of the query and flush the output stream before proceeding to the next operation. Otherwise, you may get the verdict Idleness Limit Exceed.
For flushing the output stream, please refer to the documentation of your chosen programming language. The flush functions of some common programming languages are listed below:
- C: fflush(stdout);
- C++: cout « flush;
- Java: System.out.flush();
Interaction
If the operation is a $query$ , you should output the result of the query and flush the output stream before proceeding to the next operation. Otherwise, you may get the verdict Idleness Limit Exceed.
For flushing the output stream, please refer to the documentation of your chosen programming language. The flush functions of some common programming languages are listed below:
- C: fflush(stdout);
- C++: cout « flush;
- Java: System.out.flush();
输入输出样例
输入 #1
8 set chemlabreport 1 set physicsexercise 2 set chinesemockexam 3 query physicsexercise query chinesemockexam remove physicsexercise query physicsexercise query chinesemockexam
输出 #1
1 2 -1 1
输入 #2
8 set physicsexercise 2 set chinesemockexam 3 set physicsexercise 1 query physicsexercise query chinesemockexam undo 4 query physicsexercise query chinesemockexam
输出 #2
0 1 0 -1
输入 #3
5 query economicsessay remove economicsessay query economicsessay undo 2 query economicsessay
输出 #3
-1 -1 -1
输入 #4
5 set economicsessay 1 remove economicsessay undo 1 undo 1 query economicsessay
输出 #4
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted