poj 2828 Buy Tickets
http://poj.org/problem?id=2828
格式错了几次,以为要空行,坑!!倒过来推。。
View Code
1 #include<stdio.h> 2 #define Maxn 200010 3 int n; 4 struct jiedian 5 { 6 int pos; 7 int value; 8 }jie[Maxn]; 9 struct Node 10 { 11 int l,r; 12 int sum; 13 int summ; 14 15 }node[Maxn*4]; 16 int Min(int a,int b) 17 { 18 int c; 19 return c=a>b?b:a; 20 } 21 void create_tree(int ll,int rr,int u) 22 { 23 node[u].l=ll; 24 node[u].r=rr; 25 node[u].sum=rr-ll+1; 26 27 if(ll==rr) return; 28 int mid; 29 mid=(ll+rr)>>1; 30 create_tree(ll,mid,u*2); 31 create_tree(mid+1,rr,u*2+1); 32 } 33 34 void update(int pos,int zhi,int u) 35 { 36 node[u].sum--; 37 if(node[u].l==node[u].r) 38 { 39 node[u].summ=zhi; 40 return; 41 } 42 int mid; 43 44 if(pos<=node[u*2].sum) 45 { 46 update(pos,zhi,u*2); 47 48 } 49 else{ 50 pos-=node[u*2].sum; 51 update(pos,zhi,u*2+1); 52 } 53 //node[u].sum=Min(node[u*2].sum,node[u*2+1].sum); 54 } 55 void print(int u) 56 { 57 if(node[u].l==node[u].r) 58 { 59 printf("%d",node[u].summ); 60 if(node[u].l!=n) printf(" "); 61 return; 62 } 63 print(u*2); 64 print(u*2+1); 65 66 } 67 int main() 68 { 69 int x,y; 70 while(~scanf("%d",&n)) 71 { 72 create_tree(1,n,1); 73 for(int i=0;i<n;i++) 74 { 75 scanf("%d%d",&jie[i].pos,&jie[i].value); 76 77 } 78 for(int i=n-1;i>=0;i--) 79 update(jie[i].pos+1,jie[i].value,1); 80 print(1); 81 printf("\n"); 82 } 83 }