For the maximum interval of a line segment tree, we need to handle the boundary.
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <queue> # include <vector> using namespace STD; # define maxn 222222int tree [maxn <2]; int W, H, M, OK; void buildtree (INT L, int R, int POS) {tree [POS] = W; If (L = r) return; int M = (L + r)> 1; buildtree (L, M, pos <1); buildtree (m + 1, R, (Pos <1) | 1); return;} void Update (INT Len, int L, int R, int POS) {If (L = r) {If (tree [p OS]> = Len) {printf ("% d \ n", L); tree [POS]-= Len;} else printf ("-1 \ n "); return;} int M = (L + r)> 1; int e1 = tree [POS <1]; // maximum value on the left int e2 = tree [(Pos <1) | 1]; // maximum value on the right if (E1> = Len) Update (Len, L, M, pos <1); else if (E2> = Len) Update (Len, m + 1, R, (Pos <1) | 1 ); else {printf ("-1 \ n"); return;} tree [POS] = max (tree [POS <1], tree [(Pos <1) | 1]) ;}int main () {int X; while (scanf ("% d", & H, & W, & M )! = EOF) {If (h> m) H = m; buildtree (1, h, 1); For (INT I = 0; I <m; I ++) {scanf ("% d", & X); Update (x, 1, h, 1) ;}} return 0 ;}
[HDU] billboard (line segment tree)