Test instructions
Give a h*w billboard, there are n 1*u posters, posters as far as possible, to the left of the position posted, ask each poster can be affixed to how high.
Segment Tree single point modification.
Note: since 1 <= h,w <= 10^9; 1 <= N <= 200,000, but in fact, if h>n, the worst case is just the first n rows.
So if H>n is H=n
If you do not add this sentence, because the line segment tree array to open to h<<2 so large, and h<= 10^9, so the input h too large will make the open array too large. If you add it, you won't, n<<2 is OK.
1#include <cstdio>2#include <algorithm>3 using namespacestd;4 #defineLson l,m,rt<<15 #defineRson m+1,r,rt<<1|16 Const intMaxh=200010;7 int_max[maxh<<2];8 intans;9 voidPushup (intRT)Ten { One_max[rt]=max (_max[rt<<1],_max[rt<<1|1]); A } - voidQueryintUintLintRintRT) - { the if(l==R) { -_max[rt]-=u; -ans=l; - return ; + } - intM= (l+r) >>1; + if(_max[rt<<1]>=u) A query (U,lson); at Else - query (U,rson); - pushup (RT); - } - intMain () - { in intH,w,n; - while(SCANF ("%d%d%d", &h,&w,&n)! =EOF) { to if(h>N) +H=N; - for(intI=1; I<= (h<<2); i++) the_max[i]=W; * intu; $ for(intI=0; i<n;i++){Panax Notoginsengscanf"%d",&u); - if(_max[1]<u) theprintf"-1\n"); + Else{ AQuery (U,1H1); theprintf"%d\n", ans); + } - } $ } $ return 0; -}
View Code
hdu2795 Billboard Segment Tree