Buy Tickets
Time Limit: 4000MS   Memory Limit: 65536K
Total Submissions: 17326   Accepted: 8601

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 Posi and Vali in the increasing order of i (1 ≤ i ≤ N). For each i, the ranges and meanings of Posi and Vali are as follows:

  • Posi ∈ [0, i − 1] — The i-th person came to the queue and stood right behind the Posi-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.
  • Vali ∈ [0, 32767] — The i-th person was assigned the value Vali.

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
*
poj2828 BuyTickets 线段树 给你n个pos[]和val[],表示val[i]在第pos[i]个数的右边 感觉好像做过类似的题目
对于第i个数而言,它的前面必然后pos[i]个数,所以考虑从后面往前处理
(如果顺序来的话没办法解决移位)
倒序的话我们则考虑在第i个数前面留下pos[i]个空位即可,所以利用线段树找出第
pos[i]+1个空位即可 //不知为何G++会TLE hhh-2016-03-24 15:51:59
*/
#include <algorithm>
#include <cmath>
#include <queue>
#include <iostream>
#include <cstring>
#include <map>
#include <cstdio>
#include <vector>
#include <functional>
#define lson (i<<1)
#define rson ((i<<1)|1)
using namespace std;
typedef long long ll;
const int maxn = 200020;
struct node
{
int l,r;
int num;
int mid()
{
return ((l+r)>>1);
};
} tree[maxn<<2]; void update_up(int i)
{
tree[i].num = tree[lson].num + tree[rson].num;
} void build(int i,int l,int r)
{
tree[i].l = l,tree[i].r = r; if(l == r)
{
tree[i].num = 1;
return ;
}
int mid = tree[i].mid();
build(lson,l,mid);
build(rson,mid+1,r);
update_up(i);
} void update_down(int i)
{ }
int cur;
void Insert(int i,int k)
{
if(tree[i].l == tree[i].r)
{
tree[i].num = 0;
cur = tree[i].l;
return;
}
update_down(i);
int mid = tree[i].mid();
if(k <= tree[lson].num)
Insert(lson,k);
else
Insert(rson,k-tree[lson].num);
update_up(i);
} int a[maxn],val[maxn],ans[maxn]; int main()
{
int k,n,t,m,nex;
while(scanf("%d",&n) != EOF)
{
for(int i = 1; i <= n; i++)
scanf("%d%d",&a[i],&val[i]);
build(1,1,n); for(int i = n ; i > 0; i--)
{
Insert(1,a[i]+1);
//cout << cur <<endl;
ans[cur] = val[i];
}
for(int i = 1; i <= n; i++)
{
printf("%d",ans[i]);
printf("%c",i==n ? '\n':' ');
}
}
return 0;
}

  

最新文章

  1. 在xib中用KVC修改控件属性
  2. POJ 2151 Check the difficulty of problems (概率DP)
  3. Android 自定义View,仿微信视频播放按钮
  4. HDU 2159 FATE【二维完全背包】
  5. Classic Source Code Collected
  6. OpenGL超级宝典第5版&amp;&amp;glProvokingVertex
  7. Codeforces Gym 100513I I. Sale in GameStore 暴力
  8. QT无法定位入口点QtCore4.dll(万恶的matlab啊)
  9. .where(provider).FirstOrDefault()和.FirstOrDefault(provider)的性能比较
  10. Weex的环境搭建以及集成到Android项目
  11. 四:Java使用google的thumbnailator工具对图片压缩水印等做处理
  12. .NET Core跨平台的奥秘[中篇]:复用之殇
  13. Flume的监控参数
  14. 【pycharm 密钥】pycharm 2017 密钥
  15. Linux - 查看和更改系统字符集
  16. PHP AES加密解密。
  17. Android--监听View的两个指头是放大和缩小
  18. OneZero第四周第三次站立会议(2016.4.13)
  19. php 执行命令函数
  20. [Java程序员面试宝典]读书笔记

热门文章

  1. 开始 Python 之旅
  2. 【深度学习】深入理解ReLU(Rectifie Linear Units)激活函数
  3. mongo数据库的常见操作
  4. vue.js+socket.io+express+mongodb打造在线聊天
  5. 深度学习之 cnn 进行 CIFAR10 分类
  6. 新概念英语(1-13)A new dress
  7. vue2.0+koa2+mongodb实现注册登录
  8. java集合小知识的复习
  9. Java Class文件格式详解
  10. hdu 1880 魔咒字典