CF38G.Queue
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
On a cold winter evening our hero Vasya stood in a railway queue to buy a ticket for Codeforces championship final. As it usually happens, the cashier said he was going to be away for 5 minutes and left for an hour. Then Vasya, not to get bored, started to analyze such a mechanism as a queue. The findings astonished Vasya.
Every man is characterized by two numbers: a__i, which is the importance of his current task (the greater the number is, the more important the task is) and number c__i, which is a picture of his conscience. Numbers a__i form the permutation of numbers from 1 to n.
Let the queue consist of n - 1 people at the moment. Let's look at the way the person who came number n behaves. First, he stands at the end of the queue and the does the following: if importance of the task a__i of the man in front of him is less than a__n, they swap their places (it looks like this: the man number n asks the one before him: "Erm... Excuse me please but it's very important for me... could you please let me move up the queue?"), then he again poses the question to the man in front of him and so on. But in case when a__i is greater than a__n, moving up the queue stops. However, the man number n can perform the operation no more than c__n times.
In our task let us suppose that by the moment when the man number n joins the queue, the process of swaps between n - 1 will have stopped. If the swap is possible it necessarily takes place.
Your task is to help Vasya model the described process and find the order in which the people will stand in queue when all the swaps stops.
在一个寒冷的冬夜,我们的主人公瓦西娅站在火车站的队伍中,准备购买 Codeforces 决赛的门票。正如常发生的那样,售票员声称自己将离开 5 分钟,结果却离开了整整一小时。于是瓦西娅为了不感到无聊,开始分析起“排队”这一机制。他的发现令他震惊。
每个人由两个数字刻画:ai 表示其当前任务的重要性(数值越大,任务越重要);ci 表示其良心程度。所有 ai 构成一个 1 到 n 的排列。
假设在某一时刻,队伍中已有 n−1 个人。现在我们来考察第 n 位到来者的行为。他首先站到队尾,然后执行如下操作:若他前方那个人的任务重要性 ai 小于 an,则两人交换位置(情景如下:第 n 个人向前方的人礼貌询问:“呃……不好意思,这件事对我真的非常紧急……您能让我往前挪一位吗?”),接着他继续向新的前方那人提出同样的请求,如此反复;但一旦遇到前方某人的 ai 大于 an,他就停止向前移动。此外,第 n 个人最多只能进行 cn 次这样的前移操作。
在本题中,我们假设:当第 n 个人加入队伍时,原先那 n−1 人之间的交换过程已经终止。若某次交换满足条件,则该交换必然发生。
你的任务是帮助瓦西娅模拟上述过程,并求出当所有交换都停止后,队伍中人员的最终排列顺序。
输入格式
The first input line contains an integer n which is the number of people who has joined the queue (1 ≤ n ≤ 105). In the next n lines descriptions of the people are given in order of their coming — space-separated integers a__i and c__i (1 ≤ a__i ≤ n, 0 ≤ c__i ≤ n). Every description is located on s single line. All the a__i's are different.
第一行输入包含一个整数 n,表示加入队列的人数(1 ≤ n ≤ 105)。接下来的 n 行按人员到达顺序给出每个人的描述——每行为两个用空格分隔的整数 ai 和 ci(1 ≤ ai ≤ n, 0 ≤ ci ≤ n)。所有 ai 互不相同。
输出格式
Output the permutation of numbers from 1 to n, which signifies the queue formed according to the above described rules, starting from the beginning to the end. In this succession the i-th number stands for the number of a person who will stand in line on the place number i after the swaps ends. People are numbered starting with 1 in the order in which they were given in the input. Separate numbers by a space.
输出从 1 到 n 的数字的一个排列,该排列表示按照上述规则形成的队列(从队首到队尾)。在此序列中,第 i 个数字表示在所有交换操作结束后,排在第 i 个位置上的人的编号。人的编号从 1 开始,按输入中给出的顺序依次编号。用空格分隔各数字。
输入输出样例
输入#1
2 1 0 2 1
输出#1
2 1
输入#2
3 1 3 2 3 3 3
输出#2
3 2 1
输入#3
5 2 3 1 4 4 3 3 1 5 2
输出#3
3 1 5 4 2
输入解题思路,AI测评打分。不知道怎么写?