动态开点线段树
#include<bits/stdc++.h>
using namespace std;
#define maxn 15001000
int tot = 1;
int tree[maxn];
int ls[maxn], rs[maxn];
int mark[maxn];
int n, m;
inline void push_up(int x)
{
tree[x] = tree[ls[x]] + tree[rs[x]];
return;
}
void push_down(int x, int L, int R)
{
int mid = L + ((R - L)>>1);
if(ls[x] == 0)ls[x] = ++tot;
if(rs[x] == 0)rs[x] = ++tot;
tree[ls[x]] = (mid - L + 1)*mark[x];
tree[rs[x]] = (R - mid)*mark[x];
mark[ls[x]] = mark[rs[x]] = mark[x];
//子树中的标记一定是在父节点被修改之前放进去得,所以直接用父节点的标记覆盖掉就行了
mark[x] = -1;
}
void modify(int &x, int L, int R, int l, int r, int v)
{
if(!x) x = ++tot;
if(l <= L && R <= r)
{
mark[x] = v;
tree[x] = (R - L + 1)*v;
//1代表非工作日,最后通过总天数减去非工作日天数算出答案
return;
}
if(mark[x] != -1)push_down(x, L, R);
int mid = L + ((R - L)>>1);
if(l <= mid) modify(ls[x], L, mid, l, r, v);
if(r > mid) modify(rs[x], mid + 1, R, l, r, v);
push_up(x);
return;
}
int main()
{
ios::sync_with_stdio(false);
int l, r, k;
int root = 1;
scanf("%d%d", &n, &m);
memset(mark, -1, sizeof(mark));
for(int i = 0; i < m; ++i)
{
scanf("%d%d%d", &l, &r, &k);
modify(root , 1, n, l, r, 2 - k);
printf("%d\n", n - tree[1]);
}
return 0;
}