倒着插,先不理解意思,后来看一篇题解说模拟一下

手动模拟一下就好理解了-----

不过话说一直写挫---一直改啊-----

好心塞------

 #include <cstdio>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) typedef long long LL;
const double eps = 1e-;
const int INF = ( << ) - ;
const int maxn = ; struct node{
int l,r,s;
}t[*maxn]; struct Edge{
int pos,val;
}a[maxn]; int n;
int ans[maxn]; void Push_up(int p){
t[p].s = t[p<<].s + t[p<<|].s;
} void Build_tree(int p,int l,int r){
t[p].l = l;
t[p].r = r;
if(l == r){
t[p].s = ;
return;
}
int mid = getmid(l,r);
Build_tree(p<<,l,mid);
Build_tree(p<<|,mid+,r);
Push_up(p);
} void update(int idx,int p){
if(t[p].l == t[p].r){
t[p].s--;
return;
}
int mid = getmid(t[p].l,t[p].r);
if(idx <= mid) update(idx,p<<);
else update(idx,p<<|);
Push_up(p);
} int query(int idx,int p){
if(t[p].l == t[p].r) return t[p].l;
if(t[p<<].s >= idx) return query(idx,p<<);
else return query(idx-t[p<<].s,p<<|);
} void solve(){
Build_tree(,,n);
// for(int i = 1;i <= 2*n;i++)
// printf("t[%d].l = %d t[%d].r = %d t[%d].s = %d\n",i,t[i].l,i,t[i].r,i,t[i].s);
for(int i = n;i >= ;i--){
int pos = a[i].pos;
int id = query(pos,);
ans[id] = a[i].val;
update(id,);
}
printf("%d",ans[]);
for(int i = ;i <= n;i++) printf(" %d",ans[i]);
printf("\n");
} int main(){
while(scanf("%d",&n) != EOF){
for(int i = ;i <= n;i++){
scanf("%d %d",&a[i].pos,&a[i].val);
a[i].pos++;
}
solve();
}
return ;
}

加油啊~~~~

poj 2828 Buy Tickets【线段树 单点更新】的更多相关文章

  1. POJ 2828 Buy Tickets(线段树单点)

    https://vjudge.net/problem/POJ-2828 题目意思:有n个数,进行n次操作,每次操作有两个数pos, ans.pos的意思是把ans放到第pos 位置的后面,pos后面的 ...

  2. POJ - 2828 Buy Tickets (段树单点更新)

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

  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 (线段树 or 树状数组+二分)

    题目链接:http://poj.org/problem?id=2828 题意就是给你n个人,然后每个人按顺序插队,问你最终的顺序是怎么样的. 反过来做就很容易了,从最后一个人开始推,最后一个人位置很容 ...

  5. POJ 2828 Buy Tickets 线段树 倒序插入 节点空位预留(思路巧妙)

    Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 19725   Accepted: 9756 Desc ...

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

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

  7. POJ 2828 Buy Tickets(线段树&#183;插队)

    题意  n个人排队  每一个人都有个属性值  依次输入n个pos[i]  val[i]  表示第i个人直接插到当前第pos[i]个人后面  他的属性值为val[i]  要求最后依次输出队中各个人的属性 ...

  8. POJ 2828 Buy Tickets | 线段树的喵用

    题意: 给你n次插队操作,每次两个数,pos,w,意为在pos后插入一个权值为w的数; 最后输出1~n的权值 题解: 首先可以发现,最后一次插入的位置是准确的位置 所以这个就变成了若干个子问题, 所以 ...

  9. poj 2828 Buy Tickets (线段树)

    题目:http://poj.org/problem?id=2828 题意:有n个人插队,给定插队的先后顺序和插在哪个位置还有每个人的val,求插队结束后队伍各位置的val. 线段树里比较简单的题目了, ...

  10. poj 2892---Tunnel Warfare(线段树单点更新、区间合并)

    题目链接 Description During the War of Resistance Against Japan, tunnel warfare was carried out extensiv ...

随机推荐

  1. python 整型,布尔值,字符串相关

    1.整型(int) 就是所有整数, 2.布尔值(bool) True False 0,"",[],{},(),none为False 3.字符串(str) 字符: 是单一文字符号 字 ...

  2. location.reload() 和 location.replace()的区别和应用。

    首先介绍两个方法的语法: reload 方法,该方法强迫浏览器刷新当前页面.语法:location.reload([bForceGet])  参数:bForceGet, 可选参数, 默认为 false ...

  3. Spring cloud父项目的建立

    1.建立一个maven项目 注意建立项目的时候.选择pom的包 2.添加架包 <project xmlns="http://maven.apache.org/POM/4.0.0&quo ...

  4. mysql时区错误问题及命令行登录mysql方法

    spring boot运行报错误信息“The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than ...

  5. sklearn学习2-----LogisticsRegression

    1.官网地址: http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.htm ...

  6. call和apply的使用

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. rails 安装后调整gem sources 地址

    rails 安装后调整gem sources 地址 使用https会有认证的问题: 移除原有的: gem sources --remove https://rubygems.org/ 查看当前的: g ...

  8. Codeforces Round #234 (Div. 2) A. Inna and Choose Options

    A. Inna and Choose Options time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. android AppWidget的使用以及利用TimerTask实现widget的定时更新

    第一步:首先是Widget的定义声明: 在资源文件下的xml目录中建立文件example_appwidget_info.xml: <?xml version="1.0" en ...

  10. 自己动手写CPU之第七阶段(6)——乘累加指令实现思路

    将陆续上传本人写的新书<自己动手写CPU>.今天是第29篇.我尽量每周四篇 亚马逊的销售地址例如以下,欢迎大家围观呵! http://www.amazon.cn/dp/b00mqkrlg8 ...