POJ 2828-Buy Tickets
来源:互联网 发布:战地1 为什么淘宝便宜 编辑:程序博客网 时间:2024/06/08 16:24
POJ 2828 线段树
#include<stdio.h>#include<string.h>#include<algorithm>#define lson rt<<1#define rson (rt<<1)+1using namespace std;int s[200001<<2];int a[200001],b[200001],c[200001];void build(int l,int r,int rt){ if(l==r) { s[rt]=1; return ; } int mid=(l+r)>>1; build(l,mid,lson); build(mid+1,r,rson); s[rt]=s[lson]+s[rson];}int query(int l,int r,int rt,int x){ int t; if(l==r) { s[rt]=0; return l; } int mid=(l+r)>>1; if(s[lson]>=x) t=query(l,mid,lson,x); else t=query(mid+1,r,rson,x-s[lson]); s[rt]=s[lson]+s[rson]; return t;}int main(){ int i,j,k,n,m,l; while(~scanf("%d",&n)) { for(i=0;i<n;i++) { scanf("%d %d",&a[i],&b[i]); } build(1,n,1); for(i=n-1;i>=0;i--) { int t=query(1,n,1,a[i]+1); // printf("(%d)\n",t); c[t]=b[i]; } for(i=1;i<=n;i++) { printf("%d ",c[i]); } printf("\n"); } return 0;}
0 0
- poj 2828 Buy Tickets
- poj 2828 Buy Tickets
- poj 2828 Buy Tickets
- poj 2828 Buy Tickets
- POJ 2828 Buy Tickets
- Poj 2828 Buy Tickets
- poj 2828 buy tickets
- POJ 2828 Buy Tickets
- poj 2828 Buy Tickets
- poj 2828 Buy Tickets
- POJ 2828 - Buy Tickets
- POJ 2828 - Buy Tickets
- POJ-2828-Buy Tickets
- poj 2828 Buy Tickets
- poj 2828 Buy Tickets
- poj 2828 Buy Tickets
- POJ 2828 Buy Tickets
- POJ 2828 Buy Tickets
- hdu 5687 Problem C 字典树
- HDU1847 Good Luck in CET-4 Everybody!
- 总结的java一些细节问题
- Codeforces 612C Replace To Make Regular Bracket Sequence【栈】
- HashSet用法分析
- POJ 2828-Buy Tickets
- 获取手机存储信息
- vim进阶命令(一)
- 查找一个数组中第二大的数的下标并输出
- javascript中的对象字面量为啥这么酷
- android布局之layout_weight应用
- php 安装composer
- WeX5基本使用浅析
- CSS3 RGBA的高级属性