CF916D.Jamie and To-do List

普及/提高-

通过率:0%

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 ai xiset\ a_{i}\ x_{i} — Add assignment aia_{i} to the to-do list if it is not present, and set its priority to xix_{i} . If assignment aia_{i} is already in the to-do list, its priority is changed to xix_{i} .
  • remove airemove\ a_{i} — Remove assignment aia_{i} from the to-do list if it is present in it.
  • query aiquery\ a_{i} — Output the number of assignments that are more important (have a smaller priority value) than assignment aia_{i} , so Jamie can decide a better schedule. Output 1-1 if aia_{i} is not in the to-do list.
  • undo diundo\ d_{i} — Undo all changes that have been made in the previous did_{i} days (not including the day of this operation)

At day 00 , the to-do list is empty. In each of the following qq days, Jamie will do exactly one out of the four operations. If the operation is a queryquery , 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 qq (1<=q<=105)(1<=q<=10^{5}) — the number of operations.

The following qq lines consists of the description of the operations. The ii -th line consists of the operation that Jamie has done in the ii -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 aia_{i} and an integer xix_{i} follows (1<=xi<=109)(1<=x_{i}<=10^{9}) . aia_{i} is the assignment that need to be set to priority xix_{i} .
  • If it is a remove operation, a string aia_{i} follows. aia_{i} is the assignment that need to be removed.
  • If it is a query operation, a string aia_{i} follows. aia_{i} is the assignment that needs to be queried.
  • If it is a undo operation, an integer did_{i} follows (0<=di<i)(0<=d_{i}<i) . did_{i} is the number of days that changes needed to be undone.

All assignment names aia_{i} only consists of lowercase English letters and have a length 1<=ai<=151<=|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 aia_{i} , or 1-1 if aia_{i} is not in the to-do list.

Interaction

If the operation is a queryquery , 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
    
首页