Defile
Time limit3sMemory limit1024 MB
Maintain minion healths under insert and delete, and after each update report how many would die in repeated 1-damage waves.
- Level
Medium7 of 10
- Topics
- Math, Number theory, Stack, Implementation
- Solved
- No attempts yet
Problem
Defile, a Hearthstone spell card that Junwon likes, has the following effect: "Deal 1 damage to all minions. If any die, cast this again."
In other words: represent the health of the minions currently on the board as a sequence of positive integers . Playing Defile performs the following operation on the sequence .
- Decrease all by 1.
- If any element equals 0, remove all such from the sequence and return to step 1. Increase the "number of dead minions" count by the number of removed elements. If no such exists, stop the process.
Currently there are no minions on the board. Hearthstone has many variables, but assume only the following two changes occur.
- A minion with health is added to the board.
- A minion with health is removed from the board.
After each change occurs, you must find the number of minions that die when Defile is played once.
All changes accumulate. Also note that you do not actually play Defile; you only suppose the situation in which the card is played.
Input
The first line gives , the number of changes that occur on the board. ()
The next lines each give two integers describing a change on the board. ( or , )
When , a minion with health is added to the board.
When , a minion with health is removed from the board. It is guaranteed that at least one minion with health is on the board at this time.
Output
After each change given in the input occurs, find the number of minions that would die if Defile were played, and print one per line.
Because the input and output are very large, using fast input and output is recommended.