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

  1. 4
  2. 0 77
  3. 1 51
  4. 1 33
  5. 2 69
  6. 4
  7. 0 20523
  8. 1 19243
  9. 1 3890
  10. 0 31492

Sample Output

  1. 77 33 69 51
  2. 31492 20523 3890 19243
    题目大意 :给出n个人的排队信息,aibiai表示第i个人要排在当前第ai个人的后面,bi为第i个人的标识,求出最后的队伍排列。
    思路:先把每个人的信息都记录下来,再反着插入即可。用线段树记录当前区间还有多少空位。
  1. /*
  2. * Author: Joshua
  3. * Created Time: 2014年07月15日 星期二 15时51分53秒
  4. * File Name: poj2828.cpp
  5. */
  6. #include<cstdio>
  7. #include<cstring>
  8. #define maxn 200020
  9. #define L(x) (x<<1)
  10. #define R(x) (x<<1 |1)
  11. struct node
  12. {
  13. int l,r,cnt;
  14. } e[maxn<<];
  15. int n;
  16. int pos[maxn],val[maxn],ans[maxn];
  17. void built(int t,int l,int r)
  18. {
  19. e[t].l=l;
  20. e[t].r=r;
  21. e[t].cnt=r-l+;
  22. if (l==r) return;
  23. int mid=l+((r-l+)>>)-;
  24. built(L(t),l,mid);
  25. built(R(t),mid+,r);
  26. }
  27.  
  28. void updata(int t,int x,int v)
  29. {
  30. --e[t].cnt;
  31. if (e[t].l==e[t].r)
  32. {
  33. ans[e[t].l]=v;
  34. return;
  35. }
  36. if (e[L(t)].cnt>x)
  37. updata(L(t),x,v);
  38. else
  39. updata(R(t),x-e[L(t)].cnt,v);
  40. }
  41. void solve()
  42. {
  43. for (int i=;i<=n;++i)
  44. scanf("%d%d",&pos[i],&val[i]);
  45. built(,,n);
  46. for (int i=n;i>;--i)
  47. updata(,pos[i],val[i]);
  48. for (int i=;i<=n;++i)
  49. printf("%d%c",ans[i],i==n ? '\n':' ');
  50. }
  51.  
  52. int main()
  53. {
  54. while (scanf("%d",&n)==)
  55. solve();
  56. return ;
  57. }
  1.  

poj2828 Buy ticket的更多相关文章

  1. [POJ2828] Buy Tickets(待续)

    [POJ2828] Buy Tickets(待续) 题目大意:多组测试,每组给出\(n\)条信息\((a,b)\),表示\(b\)前面有\(a\)个人,顺序靠后的信息优先级高 Solution.1 由 ...

  2. POJ2828 Buy Tickets[树状数组第k小值 倒序]

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19012   Accepted: 9442 Desc ...

  3. [poj2828] Buy Tickets (线段树)

    线段树 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must ...

  4. poj-----(2828)Buy Tickets(线段树单点更新)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 12930   Accepted: 6412 Desc ...

  5. POJ2828 Buy Tickets 【线段树】+【单点更新】+【逆序】

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 12296   Accepted: 6071 Desc ...

  6. poj2828 Buy Tickets (线段树 插队问题)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 22097   Accepted: 10834 Des ...

  7. POJ P2828 Buy Ticket——线段树的其他信息维护

    Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...

  8. poj-2828 Buy Tickets(经典线段树)

    /* Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 10207 Accepted: 4919 Descr ...

  9. POJ2828 Buy Tickets [树状数组,二分答案]

    题目传送门 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 22611   Accepted: 110 ...

随机推荐

  1. Hadoop 2.6.5 FileSystem和Configuration两个对象的探究

    Hadoop 2.6.5 FileSystem和Configuration两个对象的探究 版权声明:本文为yunshuxueyuan原创文章,如需转载,请标明出处.[http://www.cnblog ...

  2. .Net 调用微信公众号扫一扫

    1.绑定域名 去微信公众号平台中设置js接口安全域名,要注意的是不填写http://, 只填写域名即可,如 www.baidu.com. 一个月只能修改三次,要谨慎填写. 2.引入JS文件 在页面中引 ...

  3. Centos7 安装keepalived实现高可用

    场景:尝试安装keepalived实现高可用,进而在suse环境中部署. 测试过程需要配合Nginx的相关知识:Centos7 Nginx安装 1 安装过程 问题 !!! OpenSSL is not ...

  4. (转) Spring Boot MyBatis 连接数据库

    最近比较忙,没来得及抽时间把MyBatis的集成发出来,其实mybatis官网在2015年11月底就已经发布了对SpringBoot集成的Release版本,Github上有代码:https://gi ...

  5. 阿里云服务器怎么运行多个项目(Nginx)

    server { listen 80; server_name yy.test.cn; access_log /data/wwwlogs/access_nginx.log combined; root ...

  6. [BZOJ 1500]维修数列 [Splay Tree从进阶到住院]

    历尽艰辛终于A掉了这题QwQ 贴COGS评论区几句话=.= 策爷:"splay/块状链表的自虐题.".深刻理解到如果没有M倾向就不要去写这题了.. -Chenyao2333 记得b ...

  7. 基于脚本的modelsim自动化仿真笔记

    这里记录一下基于脚本的modelsim自动化仿真的一些知识和模板,以后忘记了可以到这里查找.转载请标明出处:http://www.cnblogs.com/IClearner/ . 一.基本介绍 这里介 ...

  8. C#设计模式(1)-单例模式

    单例(Singleton)模式介绍 单例模式:也可以叫单件模式,官方定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点. 单例模式的特点: 单例类只能有一个实例. 单例类必须自己创建自己的唯一 ...

  9. 移动APP云测试平台测评分析

    随着智能手机的普及率和渗透率越来越高,App开发软件也越来越多.有专家预测,2017年的App应用下载量将会突破2500亿,整个移动科技市场规模将会达到770亿美元.身处在这个"移动&quo ...

  10. IMPEX

    1.Impex是基于java Model的一种面向对象的数据操作手段,因此写impex代码前需要理清java Model之间的依赖关系. 2.基本语法:mode type[modifier=value ...