Four problems for queues and deques: a plain queue, round robin, a window of recent numbers, and a deque that keeps being reversed.
- Read a command as a
string(or achar) first, then read its number only if the command has one. - Round robin: keep pairs (job number, work left) in the queue, and the clock in
a
long long. - For the first negative in every window, the queue holds positions, not values: then you can tell which ones have slid out of the window.
- For the reversible deque, keep a
revflag. While it istrue, every command that names a side uses the other end.