Test instructions: There is a bulletin board, the size of h*w, to paste n announcements, the length of each notice is x, the height is fixed to 1, the announcement to be as far as possible on and on the left, each given a notice, request this announcement in meeting the requirements of the situation decentralized in the first layer.
Sample Input
3 5 5
2
4
3
3
3
Sample Output
1
2
1
3
-1
1# include <iostream>2# include <cstdio>3# include <cstring>4# include <algorithm>5# include <cmath>6# include <queue>7# define LLLong Long8 using namespacestd;9 Ten Const intMAXN =200010; One A intmax[maxn<<2] ;//4 times times the knot. - intH, W, N; - the voidPushup (intRt//Update to parent node - { -MAX[RT] = max (MAX[RT *2], Max[rt *2+1] );//RT is the current node. - } + - voidBuildintLintRintRt//Building a segment tree + { AMAX[RT] =W; at if(L = =R) - { - return ; - } - intm = (L + r)/2 ; -Build (L, M, RT *2) ; inBuild (M +1, R, RT *2+1) ; - to } + - intQueryintXintLintRintRt//The interval to find the maximum of the seat directly to the update operation in the query did the { * if(L = =R) $ {Panax NotoginsengMAX[RT]-=x; - returnL//each leaf node represents the row of the bulletin board the } + intm = (L + r)/2 ; A intRET =0 ; the if(MAX[RT *2] >=x) +ret = query (x, L, M, RT *2) ; - Else $ret = query (x, m+1, R, RT *2+1) ; $ pushup (RT); - returnret; - } the - intMain ()Wuyi { the //freopen ("In.txt", "R", stdin); - while(SCANF (" %d%d%d", &h, &w, &n)! = EOF)//h is high w for width n for quantity Wu { - if(H >N) Abouth =N; $Build1H1); - while(n--) - { - intx; Ascanf"%d", &x); + if(X > max[1])//if the width of an announcement is greater than that of the 1-h, the remaining width of the range is not fit. theprintf"-1\n") ; - Else $printf"%d\n", Query (x,1H1)) ; the } the } the the return 0 ; -}
View Code
HDU 2795 Bulletin Board (single point maximum)