CF916D Jamie and To-do List

Description

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.

Input Format

The first line consists of a single integer $ q $ $ (1

Output Format

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();