Codeforces Round 457 (Div. 2) |
---|
Finished |
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:
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 ≤ 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.
All assignment names ai only consists of lowercase English letters and have a length 1 ≤ |ai| ≤ 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 ai, or - 1 if ai is not in the to-do list.
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:
8
set chemlabreport 1
set physicsexercise 2
set chinesemockexam 3
query physicsexercise
query chinesemockexam
remove physicsexercise
query physicsexercise
query chinesemockexam
1
2
-1
1
8
set physicsexercise 2
set chinesemockexam 3
set physicsexercise 1
query physicsexercise
query chinesemockexam
undo 4
query physicsexercise
query chinesemockexam
0
1
0
-1
5
query economicsessay
remove economicsessay
query economicsessay
undo 2
query economicsessay
-1
-1
-1
5
set economicsessay 1
remove economicsessay
undo 1
undo 1
query economicsessay
-1
Name |
---|