The last question of the Line Segment tree is now. The line segment tree can do a lot of work, and it has higher requirements for itself when combined with DP. What you have to do is still far away ~ This question has been debugged for a long time... 1a: ask whether there is a continuous length of a empty room, if there is to live in the leftmost 2a B: [a, a + b-1] Room clearing ideas: the longest line segment tree operation in the record interval: update: interval replacement query: the leftmost breakpoint that meets the condition is queried. The main difficulty lies in void pushup (int rt, int m) {lsum [rt] = lsum [rt <1]; rsum [rt] = rsum [rt <1 | 1]; // process these steps! If (lsum [rt] = (m-m/2) lsum [rt] + = lsum [rt <1 | 1]; if (rsum [rt] = m/2) rsum [rt] + = rsum [rt <1]; msum [rt] = max (rsum [rt <1] + lsum [rt <1 | 1], max (msum [rt <1], msum [rt <1 | 1]);} Understood ~ By the way, I made another mistake on pushdown. pushdown is passed to the child node.
# Include <iostream> # include <cstdio> # include <cstring> using namespace std; # define lson rt <1, l, m # define rson rt <1 | 1, m + 1, r const int maxn = 50005; // classic practice // msum maximum continuous interval lsum, rsum from left, int cover [maxn <8], msum [maxn <8], lsum [maxn <8], rsum [maxn <8], and rsum [maxn <8]; void build (int rt, int l, int r) {cover [rt] =-1; msum [rt] = lsum [rt] = rsum [rt] = r-l + 1; if (l = r) return; int m = (l + r)> 1; build (lson); build (rson);} voi D pushdown (int rt, int m) {if (cover [rt]! =-1) {cover [rt <1] = cover [rt <1 | 1] = cover [rt]; msum [rt <1] = lsum [rt <1] = rsum [rt <1] = cover [rt]? 0: m-(m> 1 ); msum [rt <1 | 1] = lsum [rt <1 | 1] = rsum [rt <1 | 1] = cover [rt]? 0: (m> 1); cover [rt] =-1 ;}} void pushup (int rt, int m) {lsum [rt] = lsum [rt <1]; rsum [rt] = rsum [rt <1 | 1]; // process these steps! If (lsum [rt] = (m-m/2) lsum [rt] + = lsum [rt <1 | 1]; if (rsum [rt] = m/2) rsum [rt] + = rsum [rt <1]; msum [rt] = max (rsum [rt <1] + lsum [rt <1 | 1], max (msum [rt <1], msum [rt <1 | 1]);} void update (int ql, int qr, int ch, int rt, int l, int r) {if (ql <= l & qr> = r) {cover [rt] = ch; if (ch = 0) msum [rt] = lsum [rt] = rsum [rt] = r-l + 1; else if (ch = 1) msum [rt] = lsum [rt] = rsum [rt] = 0; return;} pushdown (rt, r-l + 1 ); int m = (l + r)> 1; if (ql <= m) updat E (ql, qr, ch, lson); if (qr> m) update (ql, qr, ch, rson); pushup (rt, r-l + 1 );} int query (int ch, int rt, int l, int r) {// returns the left coordinate if (l = r) return l; // haha... Pushdown (rt, r-l + 1); int m = (l + r)> 1; if (msum [rt <1]> = ch) return query (ch, lson); else if (rsum [rt <1] + lsum [rt <1 | 1])> = ch) return m-rsum [rt <1] + 1; // return the most classic else return query (ch, rson);} int main () {int n, m, a, B, c; while (scanf ("% d", & n, & m )! = EOF) {build (1, 1, n); for (int I = 1; I <= m; I ++) {scanf ("% d", & ); if (a = 1) {scanf ("% d", & B); if (msum [1] <B) // use the root node to determine whether printf ("0 \ n") is greater than B; else {int pos = query (B, 1, 1, n ); printf ("% d \ n", pos); update (pos, pos + b-1, 1, 1, n) ;}} else {scanf ("% d ", & B, & c); update (B, B + C-1, 1, n) ;}} return 0 ;}