线段树+逆序插入。

 #include <stdio.h>
#include <string.h> #define MAXN 200005
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 int space[MAXN<<];
int nums[MAXN];
int pi[MAXN], vi[MAXN];
int pos; void build(int l, int r, int rt) {
int mid;
space[rt] = r - l +;
if (l == r)
return ;
mid = (l+r)>>;
build(lson);
build(rson);
} void update(int p, int l, int r, int rt) {
int mid;
--space[rt];
if (l == r) {
pos = l;
return ;
}
mid = (l+r) >> ;
if (space[rt<<] >= p)
update(p, lson);
else {
p -= space[rt<<];
update(p, rson);
}
} int main() {
int i, n; while (scanf("%d", &n) != EOF) {
build(, n, );
for (i=; i<=n; ++i)
scanf("%d %d", &pi[i], &vi[i]);
for (i=n; i>; --i) {
update(pi[i]+, , n, );
nums[pos] = vi[i];
//printf("pos=%d\n", pos);
}
printf("%d", nums[]);
for (i=; i<=n; ++i)
printf(" %d", nums[i]);
printf("\n");
} return ;
}

【POJ】2828 Buy Tickets的更多相关文章

  1. 【POJ】2828 Buy Tickets(线段树+特殊的技巧/splay)

    http://poj.org/problem?id=2828 一开始敲了个splay,直接模拟. tle了.. 常数太大.. 好吧,说是用线段树.. 而且思想很拽.. (貌似很久以前写过貌似的,,) ...

  2. poj 2828 Buy Tickets 【线段树点更新】

    题目:id=2828" target="_blank">poj 2828 Buy Tickets 题意:有n个人排队,每一个人有一个价值和要插的位置,然后当要插的位 ...

  3. poj 2828 Buy Tickets (线段树(排队插入后输出序列))

    http://poj.org/problem?id=2828 Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissio ...

  4. POJ 2828 Buy Tickets(排队问题,线段树应用)

    POJ 2828 Buy Tickets(排队问题,线段树应用) ACM 题目地址:POJ 2828 Buy Tickets 题意:  排队买票时候插队.  给出一些数对,分别代表某个人的想要插入的位 ...

  5. poj 2828 Buy Tickets(树状数组 | 线段树)

    题目链接:poj 2828 Buy Tickets 题目大意:给定N,表示有个人,给定每一个人站入的位置,以及这个人的权值,如今按队列的顺序输出每一个人的权值. 解题思路:第K大元素,非常巧妙,将人入 ...

  6. 线段树(单点更新) POJ 2828 Buy tickets

    题目传送门 /* 结点存储下面有几个空位 每次从根结点往下找找到该插入的位置, 同时更新每个节点的值 */ #include <cstdio> #define lson l, m, rt ...

  7. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  8. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

  9. poj 2828 Buy Tickets【线段树单点更新】【逆序输入】

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 16273   Accepted: 8098 Desc ...

随机推荐

  1. iOS常见的几种延时执行的方法

    1.performSelector [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay ...

  2. linux 上不去网

    linux 上不去网   ip dns无误 ping可以到达网关 可能原因 网卡睡眠 ethtool eht0  //查看eht0网口基本设置 mii-tool -w eth0

  3. Bash从路径中获取文件名

    #!/bin/bash basename /etc/hosts

  4. delphi参数传递

    delphi参数传递 参数传递    声明/实现一个过程使用的参数称为形式参数(简称形参),调用过程时传入的参数称为实际参数(简称实参). { Info是形参} procedure ShowInfo( ...

  5. librarynotfoundforlPodsAFNetworking解决放案

    http://www.it165.net/pro/html/201503/36422.html

  6. CSS Text文本格式

    Text Color 颜色属性被用来设置文字的颜色. 颜色是通过CSS最经常的指定: 十六进制值 - 如"#FF0000" 一个RGB值 - "RGB(255,0,0)& ...

  7. 【AngularJS】——0.分析

    [引导分析]1.什么是AngularJS? 2.为什么要使用它? 3.应用场合? 4.基本思想? 5.四大核心特征? 6.优缺点是什么? 1.定义:AngularJS是一个用于设计动态web应用的前端 ...

  8. 由C到C++的学习 ----Essential C++

    一.array[] 与 vector<int> vector1 1 array[] <- 此中要填写数组的大小,而且array[]自己是不知道自己的大小的 2.1 vector< ...

  9. Binary Tree Inorder Traversal 解题思路 ×

    问题: 非递归中序遍历二叉树 思路: 1.大循环,判断节点是否为空,栈是否为空 2.不为空:点进栈,向左走 3.为空:为空,出栈,读取值,向右走

  10. 2、Python djang 框架下的word Excel TXT Image 等文件的下载

    2.python实现文件下载 (1)方法一.直接用a标签的href+数据库中文件地址,即可下载.缺点:word excel是直接弹框下载,对于image txt 等文件的下载方式是直接在新页面打开. ...