POJ-2828-Buy Tickets
来源:互联网 发布:签证cp同人文乐乎 编辑:程序博客网 时间:2024/06/08 04:27
#include<stdio.h>#include<algorithm>#include<iostream>#include<string.h>#include<stdlib.h>#include<queue>#include<vector>#include<math.h>#include<stack>#include<map>typedef long long LL;#define rtl rt<<1#define rtr rt<<1|1using namespace std;const int MAXN = 200000+10;const int MAX = 2e6+10;int n, t, cnt;struct node{ int pos, w;} lxt[MAXN];int num[MAX], a[MAX], ans[MAX];void update1(int l, int r, int value, int rt){ if(l==r) { num[rt] = value; return; } int mid = (l+r)>>1; update1(l, mid, value, rtl); update1(mid+1, r, value, rtr); num[rt] = num[rtl]+num[rtr];}void update(int pos, int w, int L, int R, int rt){ // cout<<L<<" "<<R<<" "<<w<<endl; if(L==R) { num[rt] = 0; ans[L] = w; return; } int mid = (L+R)>>1; if(pos<=num[rtl])update(pos, w, L, mid, rtl); else update(pos-num[rtl], w, mid+1, R, rtr); num[rt]--;}int main(){ while(~scanf("%d", &n)) { int k = 1; for(int i = 1; i<n; ++i) k<<=1; // cout<<"k="<<k<<endl; update1(1, n, 1, 1); // for(int i = 1; i<k; ++i)printf("%d ", num[i]);printf("\n"); for(int i = 0; i<n; ++i) scanf("%d%d", &lxt[i].pos, &lxt[i].w); for(int i = n-1; i>=0; --i) { update(lxt[i].pos+1, lxt[i].w, 1, n, 1); //for(int i = 1; i<k; ++i)printf("%d ", ans[i]);printf("\n"); } for(int i = 1; i<=n; ++i) printf("%d%c", ans[i], (i==n)?'\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
- 【初等概率论】 03
- mfc中父对话框变量获取子对话框控件的变量
- Android 小问题汇总解决
- 光线跟踪之简介
- Linux磁盘管理:LVM逻辑卷的创建及使用
- POJ-2828-Buy Tickets
- Oracle中INT、FLOAT、NUMBER区别
- VMWare中设置静态IP CentOS
- 光线跟踪之 物体表示方式
- ubuntu网页开发问题汇总[1]
- intelliJ IDEA 版本更新后,如何关闭参数提示。
- Android APK打包(多渠道)
- 1st round, 236 Lowest Common Ancestor of a Binary Tree
- 光线跟踪之 视窗与投影变换