标签:des style blog java color os
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 9895 Accepted Submission(s): 4413
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 #define N 200005 7 8 struct node{ 9 int l, r; 10 int h; 11 }a[N*4]; 12 13 int h, w; 14 15 void build(int left,int right,int root){ 16 a[root].l=left; 17 a[root].r=right; 18 a[root].h=0; 19 if(left==right) return ; 20 int mid=(left+right)/2; 21 build(left,mid,root*2); 22 build(mid+1,right,root*2+1); 23 } 24 25 int update(int height,int root){ 26 if(a[root].h+height>w) return -1; 27 if(a[root].l==a[root].r){ 28 a[root].h+=height; 29 return a[root].l; 30 } 31 int t=update(height,root*2); 32 if(t==-1) t=update(height,root*2+1); 33 if(t!=-1) a[root].h=min(a[root*2].h,a[root*2+1].h); 34 return t; 35 } 36 main() 37 { 38 int n; 39 int i, j, k, ww; 40 while(scanf("%d %d %d",&h,&w,&n)==3){ 41 if(h>200000) h=200000; 42 build(1,h,1); 43 while(n--){ 44 scanf("%d",&ww); 45 printf("%d\n",update(ww,1)); 46 47 } 48 } 49 }
HDU 2795 线段树(转变思维方能改变世界),布布扣,bubuko.com
标签:des style blog java color os
原文地址:http://www.cnblogs.com/qq1012662902/p/3857603.html