CF916D.Jamie and To-do List
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
为什么我要完成这么多作业??
杰米的学业生活越来越忙碌,他开始忘记自己需要完成的作业。于是他决定将任务记在待办事项清单上。他为每项作业分配一个优先级值(数值越小表示越重要),以便决定自己应该在哪项作业上投入更多时间。
几天后,杰米发现这份清单变得过于庞大,以至于他连清单本身都难以管理!作为杰米的好朋友,请你帮他编写一个程序,支持对这份待办事项清单执行以下操作:
_set_ _a__i_ _x__i_— 若作业 a__i 尚未出现在待办事项清单中,则将其加入清单,并将其优先级设为 x__i;若作业 a__i 已存在于清单中,则将其优先级更新为 x__i。_remove_ _a__i_— 若作业 a__i 存在于待办事项清单中,则将其从清单中移除。_query_ _a__i_— 输出比作业 a__i 更重要(即优先级值更小)的作业数量,以帮助杰米制定更合理的计划。若作业 a__i 不在待办事项清单中,则输出-1。_undo_ _d__i_— 撤销过去 d__i 天内(不包含执行该操作当天)所做的一切更改。
第 0 天时,待办事项清单为空。在接下来的 q 天中,杰米每天恰好执行上述四种操作之一。若某天的操作是 _query_,则你必须在进入下一天之前输出该查询的结果;否则可怜的杰米将无法做出恰当的决策。
输入格式
The first line consists of a single integer q (1 ≤ q ≤ 105) — 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 ≤ 109). 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.
第一行包含一个整数 $ q ( 1 \leq q \leq 10^5 $)—— 表示操作的次数。
接下来的 $ q $ 行描述了各项操作。第 $ i $ 行表示 Jamie 在第 $ i $ 天执行的操作,查询格式如下:
每行首单词表示操作类型,必须为以下四种之一:set、remove、query、undo。
- 若为
set操作,则其后跟随一个字符串 $ a_i $ 和一个整数 $ x_i ( 1 \leq x_i \leq 10^9 )。 a_i $ 是需被赋予优先级 $ x_i $ 的作业名称。 - 若为
remove操作,则其后跟随一个字符串 $ a_i 。 a_i $ 是需被移除的作业名称。 - 若为
query操作,则其后跟随一个字符串 $ a_i 。 a_i $ 是需被查询的作业名称。 - 若为
undo操作,则其后跟随一个整数 $ d_i ( 0 \leq d_i < i )。 d_i $ 表示需要撤销的天数(即回退到第 $ i - d_i $ 天结束时的状态)。
所有作业名称 $ a_i $ 仅由小写英文字母组成,且长度满足 $ 1 \leq |a_i| \leq 15 $。
保证最后一个操作一定是 query 操作。
输出格式
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.
对于每个查询操作,输出一个整数——优先级低于任务 ai 的任务数量;如果 ai 不在待办任务列表中,则输出 −1。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?