/*************************************** * ********* The subject is as follows: there is a rectangle advertisement board with H * W, and advertisements should be placed on the top; then n 1 * WI advertisements should be pasted on; and advertisements should be pasted on the left as far as possible; locate the position of the n-th advertisement. If it cannot be pasted, it is-1. algorithm idea: Use the line segment tree to calculate the maximum value of the interval; H is used to build a tree (H <= N, which is meaningless). The space stored in the tree is the space that the tree still has. If the maximum value of the Left subtree is greater than that of the tree, query the left subtree; otherwise, query the right subtree; **************************************** * ********/# include <iostream> # include <cstdio> # include <algorithm> using namespace STD; # define l, m, u <1 # define r m + 1, R, u <1 | 1 // U * 2 + 1 const Int n = 200000 + 10; int H, W, N; int A [n <2]; void build (int l, int R, int U) // U is the root node {A [u] = W; If (L = r) return; int M = (L + r)> 1; build (L ); build (r);} int query (int x, int L, int R, int U) {If (L = r) {A [u]-= X; return L;} int M = (L + r)> 1; int res = (a [U <1]> = x )? Query (x, L): Query (x, R); A [u] = max (A [U <1], a [U <1 | 1]); return res;} int main () {freopen ("C: \ Users \ Administrator \ Desktop \ kd.txt", "r", stdin); While (~ Scanf ("% d", & H, & W, & N) {If (h> N) H = N; build (1, h, 1); While (n --) {int X; scanf ("% d", & X); if (a [1] <X) printf ("-1 \ n"); else printf ("% d \ n", query (x, 1, h, 1) ;}} return 0 ;}