#P9518. queue
queue
Background
You are right, but MaiMai DX is a game and then I forgot the rest.
Problem Description
Additional note: The “queueing” here is different from the usual one. The people who are currently playing are considered the first two positions of the queue, so playing is treated as queueing.
There is an arcade with one game machine, and at most two people can play at the same time. But clearly, more than two people may come to play! So they need to line up. You need to write a program to maintain this queue, and notify the next players after others finish playing. During the whole process, the following events may happen:
-
start: A round of the game starts. If this is not the first round, then the participants of the previous round return to the back of the queue in their original order at the instant right before this round starts. Now you should output the names of the people who will play this round in the order in the queue (normally the first two people in the queue, or the only one). If there are two, separate them with a space. If nobody plays in this round, outputErrorand ignore this event. -
arrive x: arrives at the arcade and joins the back of the queue. At this time, should not already be in the queue; otherwise outputErrorand ignore this event. If the event is executed successfully, outputOK. -
leave x: leaves the arcade and leaves the queue. At this time, should be in the queue but should not be playing; otherwise outputErrorand ignore this event. If the event is executed successfully, outputOK.
You need to maintain the queue information and output what is required for the events above.
Input Format
The first line contains an integer , the number of events.
The next lines each describe one event.
Output Format
Output lines as required by the statement, representing the program’s response to each event.
14
start
arrive A
start
arrive B
arrive C
arrive D
start
leave C
leave D
start
arrive A
arrive D
leave E
start
Error
OK
A
OK
OK
OK
B C
Error
OK
A B
Error
OK
Error
C D
3
arrive A
arrive B
arrive C
OK
OK
OK
Hint
Sample Explanation
In sample , the following events happen:
- At the first
start, the queue is empty, so outputError. Athen joins the queue.- At the second
start, there is onlyA, so outputA. B, C, Dthen join the queue in order.- At the third
start,B, Cplay. Ctries to leave, but he is playing, so outputError.Dleaves successfully.- At the fourth
start,A, Bplay. Atries to join the queue, but he is already in the queue, so outputError.Djoins the queue again.Etries to leave, but is not in the queue at all, so outputError.- At the fifth
start,C, Dplay.
In sample , A, B, C join the queue in order. All operations are legal, so output three OK.
Constraints
For of the testdata, it is guaranteed that .
For of the testdata, it is guaranteed that .
For another of the testdata, it is guaranteed that there is no leave operation.
For another of the testdata, names can only be a single uppercase letter.
For of the testdata, it is guaranteed that , and each name contains only uppercase and lowercase letters and has length at most .
The input and output size of this problem is large, so please use efficient I/O methods.
Translated by ChatGPT 5