func_code_string: #include <bits/stdc++.h>   using namespace std;   struct segnode {     int l, r, mid, s, h;     segnode *ls, *rs;     segnode(void) { l = r = mid = s = h = 0; }     segnode(int x, int y) { l = x, r = y, mid = (l + r) >> 1, s = h = 0; }     void build(void) {       if (l == r) return;       ls = new segnode(l, mid);       rs = new segnode(mid + 1, r);       ls->build();       rs->build();     }     void upd(int x, int y) {       if (l == r) {         s = y > 0, h = y;         return;       }       if (x <= mid)         ls->upd(x, y);       else         rs->upd(x, y);       s = ls->s + rs->s;     }     int findx(int x, int &dh) {       if (l == r) {         dh = h;         return l;       }       if (x <= ls->s)         return ls->findx(x, dh);       else         return rs->findx(x - ls->s, dh);     }     int findy(int x) {       if (l == r) return h;       if (x <= mid)         return ls->findy(x);       else         return rs->findy(x);     }     void mupd(int x, int y) {       if (l == r) {         s = y;         return;       }       if (x <= mid)         ls->mupd(x, y);       else         rs->mupd(x, y);       s = max(ls->s, rs->s);     }     int mget(int x, int y) {       if (x <= l && r <= y) return s;       int t = 0;       if (x <= mid) t = ls->mget(x, y);       if (y > mid) t = max(rs->mget(x, y), t);       return t;     }     void print(void) {       printf( [%d,%d %d %d] n , l, r, mid, s);       if (l == r) return;       ls->print();       rs->print();     }   };   segnode sy, sx;   segnode ty, tx;   int n, m, mm;   void init(void) {     mm = m + 11;     sy = segnode(0, mm);     sx = segnode(0, n);     ty = segnode(0, mm);     tx = segnode(0, n);     sy.build();     sx.build();     ty.build();     tx.build();   }   void msort(int *x, int *y, int n) {     pair<int, int> a[20];     for (int i = 1; i <= n; i++) a[i].first = x[i], a[i].second = y[i];     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) x[i] = a[i].first, y[i] = a[i].second;   }   int main(void) {     scanf( %d%d , &n, &m);     init();     for (int t = 1, x, y, z; t <= m; t++) {       scanf( %d%d , &x, &y);       static int ti[20], hi[20];       if (x == 1) {         scanf( %d , &z);         int dz = z;         z = z - t + m;         tx.upd(y, z), ty.upd(z, y);         int dt = 0;         for (int i = 1; i <= dz; i++) {           int id = i - t + m;           ti[++dt] = ty.findy(id), hi[dt] = id;           if (!ti[dt])             dt--;           else             sy.mupd(id, 0), sx.mupd(ti[dt], 0);         }         msort(hi, ti, dt);         for (int i = dt; i >= 1; i--) {           int s = sx.mget(ti[i] + 1, n) + 1;           sy.mupd(hi[i], s), sx.mupd(ti[i], s);         }       } else {         for (int i = 1; i <= y; i++) {           int h, id = tx.findx(i, h);           ti[i] = id, hi[i] = h;           sy.mupd(h, 0), sx.mupd(id, 0);           if (i == y) tx.upd(id, 0), ty.upd(h, 0);         }         for (int i = y - 1; i >= 1; i--) {           int s = sy.mget(hi[i] + 1, mm) + 1;           sy.mupd(hi[i], s), sx.mupd(ti[i], s);         }       }       printf( %d n , sy.mget(0, mm));     }     return 0;   }   