题目传送门

 /*
结点存储下面有几个空位
每次从根结点往下找找到该插入的位置,
同时更新每个节点的值
*/
#include <cstdio>
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1 const int MAX_N = + ;
int pos[MAX_N], val[MAX_N];
int sum[MAX_N << ];
int que[MAX_N];
int id; void build(int l, int r, int rt)
{
sum[rt] = r - l + ; //节点有多少个空位置
if (l == r) return ;
int m = (l + r) >> ;
build (lson);
build (rson);
} void update(int p, int l, int r, int rt)
{
sum[rt]--; //插入一个减少一个空位置
if (l == r) //找到了传递该位置
{
id = l;
return ;
}
int m = (l + r) >> ;
if (p <= sum[rt<<])
{
update (p, lson);
}
else
{
p -= sum[rt<<]; //减去
update (p, rson);
}
} int main(void) //POJ 2828 Buy tickets
{
//freopen ("inE.txt", "r", stdin);
int n; while (~scanf ("%d", &n))
{
build (, n, );
for (int i=; i<=n; ++i)
{
scanf ("%d%d", &pos[i], &val[i]);
}
for (int i=n; i>=; --i) //最后插入的位置不变
{
update (pos[i]+, , n, );
que[id] = val[i];
}
printf ("%d", que[]);
for (int i=; i<=n; ++i)
{
printf (" %d", que[i]);
}
puts ("");
} return ;
}

最新文章

  1. HTML5中id可以用数字开头,但在css中不能正常使用
  2. 常用的JavaScript模式
  3. html5 video标签兼容性与自定义控件
  4. 对redis客户端jedis2.8.0的进一步封装
  5. 中文简体windows CMD显示中文乱码解决方案
  6. C++程序设计实践指导1.2二维数组的操作运算改写要求实现
  7. 批量 GBK 转 UTF8 java
  8. 分页:T-SQL存储过程和EF存储过程的使用
  9. 重读The C programming Lanuage 笔记二:运算符优先级
  10. MongoDB数据库的数据类型和$type操作符
  11. Openresty 数据共享API.Data Sharing within an Nginx Worker
  12. C#以管理员用户打开某个程序
  13. [No0000FB]C# 命名空间(Namespace)
  14. Spring framework3.2整合hibernate4.1报错:No Session found for current thread
  15. 下载8000首儿歌的python代码
  16. springboot 注解版案例
  17. ubuntu16.04中开启和关闭防火墙
  18. Linxu内核参数详解
  19. 年假小 Plan
  20. Python 爬虫 学习一

热门文章

  1. WPF绑定各种数据源之object数据源
  2. mac Git本地服务器配置
  3. 浏览器和服务器 对post get请求 url长度限制
  4. Educational Codeforces Round 10 D. Nested Segments
  5. react项目中的注意点
  6. react native 中的redux
  7. tload
  8. 设置linux服务器下开放端口
  9. 【Codeforces 20C】 Dijkstra?
  10. 【USACO06NOV】路障