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 ≤ iN). 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

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.

题意有n个人,给出每一个人每次插入的位置。和这个人的价值。输出最后的价值顺序。由于队伍是动态变化的所以能够从最后一次插入往前插入。cc[o]维护节点o所相应区间能插入的人数,插入时假设左边能插入就插在左边,否则插在右边,递归到叶节点为止。。。

/*************************************************************************
> File Name: f.cpp
> Author: acvcla
> QQ:
> Mail: acvcla@gmail.com
> Created Time: 2014年10月04日 星期六 22时39分16秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
int cc[maxn<<2],ans[maxn];
int loc[maxn],val[maxn];
void built(int o,int l,int r){
if(l==r){
cc[o]=1;
return;
}
int M=(l+r)>>1;
built(o<<1,l,M);
built(o<<1|1,M+1,r);
cc[o]=cc[o<<1]+cc[o<<1|1];
}
int x,w;
void Modify(int o,int l,int r)
{
cc[o]--;
if(l==r){
ans[l]=w;
return;
}
int M=(l+r)>>1;
if(cc[o<<1]>=x){
Modify(o<<1,l,M);
return ;
}
x-=cc[o<<1];
Modify(o<<1|1,M+1,r);
}
int main(){
int n;
while(~scanf("%d",&n)){
built(1,1,n);
rep(i,1,n){
scanf("%d%d",loc+i,val+i);
}for(int i=n;i>=1;i--){
x=loc[i]+1,w=val[i];
Modify(1,1,n);
}
printf("%d",ans[1]);
rep(i,2,n)printf(" %d",ans[i]);
printf("\n");
}
return 0;
}

最新文章

  1. Bzoj1597 [Usaco2008 Mar]土地购买
  2. sqlserver 性能优化常用方法
  3. 关于xml配置实现AOP的小知识
  4. 教你搭建SpringSecurity3框架( 更新中、附源码)
  5. Insus Search Utility Ver2
  6. dojo 资源库
  7. ORCLE INNODB 博客与 innodb_lru_scan_depth
  8. html lang
  9. exp/imp 有很多弊端
  10. js console.log 打印 对像 数组 详解
  11. Android应用程序绑定服务(bindService)的过程源代码分析
  12. UGUI Image控件
  13. ##7.Dashboard web管理界面-- openstack pike
  14. python标准库之operator(运算符模块)
  15. Ubuntu18.04+GTX1080Ti+CUDA9.0+cuDNN7.0+TensorFlow-GPU1.9环境搭建【2018年11月配置成功】
  16. CentOS7下Django环境的搭建安装python3.6.5,virtualenv django1.11.14
  17. Jenkins高危代码执行漏洞检测/开源漏洞靶场
  18. Linux上shell脚本,字符串转ASCII码
  19. Java CMYK图片转RGB图片(TwelveMonkeys方式)
  20. easyui---easyloader.js

热门文章

  1. MySQL好弱智的一个错误
  2. caioj 1077 动态规划入门(非常规DP1:筷子)
  3. 我的投资案例(3)-看好互联网和金融两大朝阳行业,参投入股垂直金融招聘平台&quot;职业梦CareerDream.cn&quot;
  4. unity SystemInfo类 获得电量battery
  5. JDBC连接SQL Server 2005 报错Connection refused: connect
  6. Codeforces Round #313 (Div. 2) 解题报告
  7. POJ 3014:Asteroids(二分匹配,匈牙利算法)
  8. Sqlite 命令行导出、导入数据(直接支持CSV)
  9. powerpoint(ppt) 的制作
  10. Sqoop-1.4.6工具import和export使用详解(官网)