To-Do List
시간 제한2초메모리 제한2048 MB
시작 시각과 소요 시간이 있는 과제가 삽입과 삭제로 바뀔 때, 매 갱신 후 모든 과제를 가장 일찍 끝내는 시각을 구한다.
문제
Wow, your to-do list is empty...but not for long! Over the next few seconds, you’ll have to handle updates to your to-do list.
For the first type of update, you will have to add a new homework assignment to your to-do list. This assignment will be released at the beginning of second , and will take seconds to complete (). For the second type of update, you will have to remove the -th homework assignment that was added to your to-do list.
After each update, you wonder: what’s the earliest time you can finish all of the homework assignments in your to-do list? You can only work on one assignment at a time, and you must finish a homework assignment once you start it without switching to another assignment.
입력
The first line of input contains an integer ().
The next lines each contain a line starting with a character A or D. A line starting with A represents the first type of update and ends with two space-separated encrypted∗ integers and . A line starting with D represents the second type of update and ends with an encrypted integer . It is guaranteed that there have been at least assignments added and that the -th assignment to be added has not been removed yet.
It is guaranteed that there is at least one homework assignment on your to-do list after every update.
∗Note that the input for this problem is encrypted. To decrypt and obtain the actual values of , , and , you may use the following formulas:
Here, represents the answer after the previous update and is initially before any updates. It may also be useful to note that mod corresponds to the % operator in most programming languages, indicating the remainder after division. For example, and .
출력
Output lines, where the -th line contains the earliest time (in seconds) you can finish all of the homework assignments in your to-do list after the -th update.