← 返回 google 的题目列表Determine Passing Order and Crossing Times for People Entering/Exiting a Door
类型:online_judge
You are given an array events grouped by person index. events[i] is a tuple (t, action) for person i:
t is an integer timestamp.
action is either "enter" or "exit".
Assume each person appears exactly once (either enter or exit). A single door can be used by at most one person per time unit. You must compute the actual time each person passes through the door, since multiple requests at the same time create queues.
Return an array ans where ans[i] is the time person i actually uses the door.
If at the same time t there are both entering and exiting requests, the priority rules are:
If at the previous time t-1 someone used the door to enter, then enter has priority at time t.
If at the previous time t-1 someone used the door to exit, then exit has priority at time t.
If nobody used the door at time t-1, then exit has priority at time t.
Within the same action type (all enter or all exit), people are processed in increasing index order.
Simulation starts from the earliest timestamp. If there is a gap where no one is waiting and no new arrivals, time may jump to the next earliest event timestamp.
Input (stdin)
Line 1: integer n (number of people)
Next n lines: i t action
i: person index (0..n-1)
t: timestamp
action: enter or exit
Each i appears exactly once.
Output (stdout)
Print n lines, where line k is ans[k].
Constraints
1 <= n <= 2 * 10^5
0 <= t <= 10^9
Example
Input:
4
0 0 enter
1 0 exit
2 1 enter
3 1 exit
Output:
2
0
3
1
Example
Input
4
0 0 enter
1 0 exit
2 1 enter
3 1 exit
Output
2
0
3
1