标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 13050 Accepted Submission(s):
5651
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 struct node 7 { 8 int l,r; 9 int mmax; 10 } s[200000*4]; 11 12 void InitTree(int l,int r,int k,int w) 13 { 14 s[k].l=l; 15 s[k].r=r; 16 s[k].mmax=w; 17 if (l==r) 18 return ; 19 int mid=(l+r)/2; 20 InitTree(l,mid,2*k,w); 21 InitTree(mid+1,r,2*k+1,w); 22 } 23 24 void UpdataTree(int num,int k)//进行点的更新 25 { 26 if (s[k].r==s[k].l) 27 { 28 printf ("%d\n",s[k].l); 29 s[k].mmax-=num; 30 return ; 31 } 32 if (num<=s[k*2].mmax) 33 UpdataTree(num,k*2); 34 else 35 UpdataTree(num,k*2+1); 36 s[k].mmax=s[k*2].mmax>s[k*2+1].mmax?s[k*2].mmax:s[k*2+1].mmax; 37 } 38 39 int main () 40 { 41 int h,w,n,a; 42 while (~scanf("%d%d%d",&h,&w,&n)) 43 { 44 int hh=h>n?n:h; 45 InitTree(1,hh,1,w); 46 for (int i=1; i<=n; i++) 47 { 48 scanf("%d",&a); 49 if (a<=s[1].mmax) 50 UpdataTree(a,1); 51 else 52 printf ("-1\n"); 53 } 54 } 55 return 0; 56 }
标签:
原文地址:http://www.cnblogs.com/qq-star/p/4442784.html