Incinerator
Time limit2sMemory limit512 MB
Maintain a queue of waste and M incinerator cells under burn, query, append, and recycle commands, then report the final cells.
- Level
Medium7 of 10
- Topics
- Implementation, Queue, Array, Simulation
- Solved
- No attempts yet
Problem
Jongyeong wants to burn pieces of waste in order. There are kinds, numbered through . The kinds in queue order form the sequence . More waste to burn can be added to the back of the queue later.
The incinerator has cells in a row, numbered to from the left. At the start, take pieces from the front of the queue and place them in order into cells through . If , the cells on the right stay empty.
One burning operation burns everything in a consecutive interval () at once. After burning, cells are empty, so refill them in order from cell with pieces taken in order from the front of the queue. If the queue runs out while refilling, leave the remaining cells empty.
Write a program that performs the following four kinds of commands times in total.
- Burn the interval of the incinerator.
- Print the kind in cell of the incinerator.
- Append pieces of kind to the back of the current queue.
- Remove pieces from the front of the current queue for recycling.
After all commands, also print the current state of the incinerator.
Input
The first line holds in order. ()
The second line holds integers . ()
Each of the next lines holds one command. Every line starts with an integer giving the command kind. ()
- If , it is the first command, followed by and . ()
- If , it is the second command, followed by . ()
- If , it is the third command, followed by and . (, )
- If , it is the fourth command, followed by . ( the number of pieces currently in the queue)
The second command appears at least once.
Output
On the first line, print the answers to all second commands in order, separated by spaces. On the second line, print the kinds left in the incinerator from cell to cell in order, separated by spaces, after all commands. Print for an empty cell.