POJ 2828 Buy Tickets
来源:互联网 发布:linux telnet命令 编辑:程序博客网 时间:2024/06/06 02:04
Sample Input
4
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492
Sample Output
77 33 69 51
31492 20523 3890 19243
Hint
4
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492
Sample Output
77 33 69 51
31492 20523 3890 19243
Hint
The figure below shows how the Little Cat found out the final order of people in the queue described in the first test case of the sample input.
<pre name="code" class="cpp">#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>#define MAXN 200010using namespace std;struct point{ int index; int data;}p[200010];int vis[200010];struct node{ int l,r; int sum;}a[MAXN<<2];void pushup(int index){ a[index].sum = a[index<<1].sum+a[index<<1|1].sum;}void build(int l,int r,int index){ a[index].l = l; a[index].r = r; if(l == r){ a[index].sum = 1; return ; } int mid = (l+r)>>1; build(l,mid,index<<1); build(mid+1,r,index<<1|1); pushup(index);}void updata(int pos,int index,int val){ if(a[index].l == a[index].r){ a[index].sum = 0; vis[a[index].l] = val; return ; } //判断位置 if(pos <= a[index<<1].sum){ updata(pos,index<<1,val); } else{ updata(pos-a[index<<1].sum,index<<1|1,val); } pushup(index);}int main(){ int n; while(~scanf("%d",&n)){ for(int i = 0; i < n; i++){ scanf("%d %d",&p[i].index,&p[i].data); p[i].index++; } build(1,n,1); for(int i = n-1; i >= 0; i--){ //从后向前;因为在后面的位置是确定的 updata(p[i].index,1,p[i].data); } for(int i = 1; i <= n; i++){ printf("%d ",vis[i]); /* if(i == n) printf("\n"); else printf(" "); 超时 */ } 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
- 关于LCA(Tarjan+ST)
- CENTOS 6.5 配置YUM安装NGINX
- 二叉树的建立和基础操作<三> —— (三种遍历及分层打印)
- HTML5地理位置Geolocation以及百度地图应用
- Python的多版本如何处理--请使用pyenv
- POJ 2828 Buy Tickets
- Ubuntu中文系统超级终端使用英文提示
- UVA11461Square Numbers
- css 新颖的表单边框
- Android中文API(141) —— GridLayout
- C++ inline函数相关总结
- Ajax
- php同时使用session和cookie来保存用户登录信息
- 主要看设置缓存算法