/* Paste the code of the cool. The code you write is ugly. Don't mention how disgusting it is... type: Line Segment tree + latency tag + interval merge... */# include <iostream> # include <cstring> # include <cctype> # include <cstdio> # include <algorithm> using namespace STD; # define L (r) r <1 # define R (r) r <1 | 1 const int maxm = 50005; typedef struct {int lsum, rsum, msum; // maximum number of rooms on the left, respectively, maximum number of rooms on the right, total maximum number of rooms int cover; // whether to stay} node; node tree [maxm <2]; void Pushdown (INT root, int m) // update {If (tree [root]. cover =-1) return; // whether it has been changed New tree [L (Root)]. cover = tree [R (Root)]. cover = tree [root]. cover; tree [L (Root)]. msum = tree [L (Root)]. lsum = tree [L (Root)]. rsum = tree [root]. cover? 0: M-(M> 1); tree [R (Root)]. msum = tree [R (Root)]. lsum = tree [R (Root)]. rsum = tree [root]. cover? 0 :( m> 1); tree [root]. cover =-1;} void pushup (INT root, int m) // update {tree [root] upwards. lsum = tree [L (Root)]. lsum; tree [root]. rsum = tree [R (Root)]. rsum; If (tree [root]. lsum = m-(M> 1) tree [root]. lsum + = tree [R (Root)]. lsum; // merge the IF (tree [root]. rsum = (M> 1) tree [root]. rsum + = tree [L (Root)]. rsum; tree [root]. msum = max (tree [R (Root)]. lsum + tree [L (Root)]. rsum, max (tree [L (Root)]. msum, tree [R (Root)]. msum);} void create (INT L, Int R, int root) // build process {tree [root]. cover =-1; tree [root]. lsum = tree [root]. rsum = tree [root]. msum = r-L + 1; if (L = r) {return;} int mid = (L + r)> 1; Create (L, mid, L (Root); Create (Mid + 1, R, R (Root);} void Update (int ll, int RR, int C, int L, int R, int root) // update {If (LL <= L & R <= RR) // if this range is found, a value is directly returned, do not continue to update {tree [root]. msum = tree [root]. lsum = tree [root]. rsum = C? 0: R-l + 1; tree [root]. cover = C; return;} Pushdown (root, R-l + 1 ); // update int M = (L + r)> 1; if (LL <= m) Update (LL, RR, C, l, M, L (Root); If (M <RR) Update (LL, RR, C, M + 1, R, R (Root); pushup (root, r-l + 1); // report the node information to the parent node after the downstream update.} int query (int w, int L, int R, int root) // query the leftmost node that meets the number of consecutive rooms {If (L = r) return l; Pushdown (root, R-l + 1 ); // update int M = (L + r)> 1 when the subnode of this node is used; ////////////// pay attention to the sequence. If (tree [L (Root)] For interval processing. Msum> = W) return query (W, L, M, L (Root )); // If the left son is satisfied, ask the left son else if (tree [L (Root)]. rsum + tree [R (Root)]. lsum> = W) return M-tree [L (Root)]. rsum + 1; // if the number between the left son and the right son is satisfied, the number else return query (W, m + 1, R, R (Root); // if neither of them is met, ask the right son} int main () {int n, m; while (~ Scanf ("% d", & N, & M) {create (1, n, 1); int A, num, x, D, P; for (INT I = 0; I <m; ++ I) {scanf ("% d", & A); if (1 =) {scanf ("% d", & num); If (tree [1]. msum <num) puts ("0"); // if the maximum number of consecutive rooms in the entire interval is smaller than the predefined number, the output is 0 else {P = query (Num, 1, n, 1); // find the leftmost node P printf ("% d \ n", P); Update (p, p + num-1, N, 1 ); // mark an existing room} else {scanf ("% d", & X, & D); Update (x, x + D-1, 0, 1, n, 1); // mark the room in this range as nobody} return 0 ;}