标签:art for contract mos show case possible ref can
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 20772 Accepted Submission(s): 8598
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 6 static const int maxm=1e6+10; 7 8 int tr[maxm],left[maxm],right[maxm]; 9 10 void build(int num,int l,int r,int w){ 11 left[num]=l;right[num]=r; 12 if(l==r){tr[num]=w;return;} 13 int mid=(l+r)>>1; 14 build(num<<1,l,mid,w); 15 build(num<<1|1,mid+1,r,w); 16 tr[num]=max(tr[num<<1],tr[num<<1|1]); 17 } 18 19 void insert(int num,int width){ 20 if(left[num]==right[num]&&tr[num]>=width){printf("%d\n",left[num]);tr[num]-=width;return;} 21 else{ 22 if(width<=tr[num<<1])insert(num<<1,width); 23 else insert(num<<1|1,width); 24 tr[num]=max(tr[num<<1],tr[num<<1|1]); 25 } 26 } 27 28 int main(){ 29 int h,n,w; 30 while(scanf("%d%d%d",&h,&w,&n)!=EOF){ 31 build(1,1,min(h,n),w); 32 for(int i=1;i<=n;i++){ 33 int x;scanf("%d",&x); 34 if(x>tr[1])printf("-1\n"); 35 else insert(1,x); 36 } 37 } 38 39 return 0; 40 }
标签:art for contract mos show case possible ref can
原文地址:http://www.cnblogs.com/Exbilar/p/6390495.html