AmazonOA #328
Process Queue
估计中等可在线判题
考点(AI 标注)模拟/实现原地数组
All processes start in the queue, and wait[i] is the deadline, counted from time 0, up to which process i can wait. Time t starts at 0. Each second, first process and remove the one process at the head of the queue, then remove every other remaining process whose deadline is ≤t, including expired items in the middle or at the end of the queue. Record the number remaining at the end of that second, until the queue is empty; the initial n before any processing is not recorded.
输入格式
The first line contains n and the second line contains wait. On this site 1≤n≤200000, 0≤wait[i]≤10^9, and a deadline of 0 is valid. The last output item must be 0.
输出格式
Output the queue length at the end of each second, separated by spaces, ending with 0.
样例 1
输入:
4
2 2 3 1
输出:
3 1 0
样例 2
输入:
5
4 3 1 2 1
输出:
4 1 0
样例 3
输入:
3
0 0 9
输出:
1 0
样例说明
The answers are 3 1 0; 4 1 0; and 1 0. In the third example, at time 0 the first 0 at the head is removed first, then the other expired 0 is removed, and 9 is left to be processed at time 1. The source only clears expired items at the head, so it misses those in the middle and at the end.