1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #include <cstdio> #include <cctype> #include <algorithm> using namespace std; const int N = 200010; const int M = 500010<<1; inline int read() { int x = 0,f = 1;char v = getchar(); while (!isdigit(v)) {if (v =='-') f = -1;v = getchar();} while (isdigit(v)) {x = x * 10 + v - 48;v = getchar();} return x * f; }
struct node { int l,r,num,tag; }tree[N<<2];
inline void build(int p,int l,int r) { tree[p].l = l;tree[p].r = r; if (l == r) { tree[p].num = 1; return ; } int mid = (l + r) >> 1; build (p << 1,l,mid); build (p << 1 | 1,mid + 1,r); tree[p].num = tree[p<<1].num + tree[p << 1 | 1].num; return; }
inline void spread(int p) { if (!tree[p].num) { tree[p<<1].num = tree[p<<1|1].num = 0; } }
inline void change (int p,int x,int y) { if (tree[p].l >= x && tree[p].r <= y) { tree[p].num = 0; return ; } spread(p); int mid = (tree[p].l + tree[p].r) >> 1; if (mid >= x) change(p<<1,x,y); if (mid < y) change(p<<1|1,x,y); tree[p].num = tree[p<<1].num + tree[p<<1|1].num; return ; }
int main() { int n = read(),m = read(); build (1,1,n); for (int i = 1;i <= m;++i) { int x = read(),y = read(); change(1,x,y); printf("%d\n",tree[1].num); } return 0; }
|