#SFJSJJZN0X49D04. Buy Tickets
Buy Tickets
题目描述
达达在买回家的火车票,因为正值春运,售票处排起了长队。
因为晚上室内光线很暗,所以很多人趁机插队。
现在给每个人赋予一个整数作为编号,告诉你每一个排队的人的编号,和他进入队列时的具体位置。
请你确定最终的队列顺序。
输入格式
输入可能包含多组测试用例。
对于每组测试用例,第一行包含整数 N,表示排队的总人数。
接下来 N 行,每行两个整数 Pi,Vi,第 i 行数据表示第 i 个人进入队列时的位置以及他的个人编号。
一个人的 Pi 值具体表示为当该人员进入队列时,他前面的人数。
例如,如果一个人插到了队首,则其 Pi 值为 0,如果插到了第三个位置(第二个人后面),则其 Pi 值为 2。
输出格式
每个测试用例,输出一行包含 N 个整数(表示每个人的编号)的结果,表示最终的人员队列顺序。
每个结果占一行,同行数据之间空格隔开。
数据范围
1≤N≤200000, 0≤Vi≤32767, 0≤Pi≤i−1
输入样例:
4
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492
输出样例:
77 33 69 51
31492 20523 3890 19243
样例解释
下图描述了输入样例中第一组测试用例的场景。
Description
Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…
The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had to travel by train to Mianyang, Sichuan Province for the winter camp selection of the national team of Olympiad in Informatics.
It was one o’clock a.m. and dark outside. Chill wind from the northwest did not scare off the people in the queue. The cold night gave the Little Cat a shiver. Why not find a problem to think about? That was none the less better than freezing to death!
People kept jumping the queue. Since it was too dark around, such moves would not be discovered even by the people adjacent to the queue-jumpers. “If every person in the queue is assigned an integral value and all the information about those who have jumped the queue and where they stand after queue-jumping is given, can I find out the final order of people in the queue?” Thought the Little Cat.
Input
There will be several test cases in the input. Each test case consists of N + 1 lines where N (1 ≤ N ≤ 200,000) is given in the first line of the test case. The next N lines contain the pairs of values and in the increasing order of i (1 ≤ i ≤ N). For each i, the ranges and meanings of and are as follows:
- ∈ [0, i − 1] — The i-th person came to the queue and stood right behind the -th person in the queue. The booking office was considered the 0th person and the person at the front of the queue was considered the first person in the queue.
- ∈ [0, 32767] — The i-th person was assigned the value .
There no blank lines between test cases. Proceed to the end of input.
Output
For each test cases, output a single line of space-separated integers which are the values of people in the order they stand in the queue.
Sample Input
4
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492
Sample Output
77 33 69 51
31492 20523 3890 19243
Hint
The figure below shows how the Little Cat found out the final order of people in the queue described in the first test case of the sample input.