poj_2828线段树,逆序插入
来源:互联网 发布:sql将a表数据复制到b表 编辑:程序博客网 时间:2024/06/03 19:02
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn = 200020;using namespace std;int p[200020],v[200020];int sum[maxn<<2];int ans[maxn];void build(int l,int r,int rt){ sum[rt]=r-l+1; int m=(r+l)/2; if(l==r) return; build(lson); build(rson);}void update(int v,int p,int l,int r,int rt){ sum[rt]--; int m=(r+l)/2; if(l==r) { ans[l]=v; return ; } if(sum[rt<<1]>=p) { update(v,p,lson); } else { p-=sum[rt<<1]; update(v,p,rson); }}int main(){ int n; while(cin>>n) { for(int i=0; i<n; i++) scanf("%d%d",&p[i],&v[i]); build(1,n,1); for(int i=n-1; i>=0; i--) update(v[i],p[i]+1,1,n,1); cout<<ans[1]; for(int i=2; i<=n; i++) cout<<" "<<ans[i]; cout<<endl; } return 0;}
0 0
- poj_2828线段树,逆序插入
- poj_2828 Buy Tickets(线段树)
- Buy Tickets----POJ_2828----线段树之单点更新
- poj2828 经典线段树应用 逆序插入
- POJ 2828 逆序插入加线段树
- POJ 2828 线段树 逆序插入
- poj 2828 Buy Tickets(线段树,逆序插入)
- poj 2828 线段树(单点更新,逆序插入)
- POJ2828线段树+逆序
- poj 2828 Buy Tickets 【线段树】【逆序插入 + 单点更新 + 区间求和】
- poj2299(逆序数+线段树)
- 线段树_逆序数
- 线段树---求逆序数
- hdu1394 逆序数-线段树
- 线段树求逆序数
- 线段树--求逆序数
- hdu 1394(线段树求逆序数)
- 线段树求逆序数 hdu1394
- 减肥的最佳年龄
- 与NULL 有关的几个函数
- poj3233 Matrix Power Series,矩阵快速幂
- JavaWeb---用户自定义标签
- JavaWeb---自定义带参参数
- poj_2828线段树,逆序插入
- 十:申请微信公众号和搭建SAE网上服务器
- HdU 4046 Panda 线段树
- HDOJ 3530 Subsequence(单调队列(含单调队列详解))
- Android OpenGL ES 开发教程(15):通用的矩阵变换指令
- win7系统下Python、Numpy、NLTK、Matplotlib等的安装【python自然语言处理所需
- Codeforces Round #260 (Div. 2) B. Fedya and Maths
- 经验之谈:问题定位原则
- Quartus II的USB blaster驱动安装--经典收藏