这个人很懒,什么都没写
https://kirka.io
T169
290282
#include <bits/stdc++.h>
#define int long long int
using namespace std;
const int MAXQ = 3e5 + 5;
int n, q, rt, tot;
struct Node {
int l, r, ls, rs, sum, lazy;
}tree[MAXQ * 30];
void pushup(int p) {
tree[p].sum = tree[p << 1].sum + tree[p << 1 | 1].sum;
}
void Xg(int &p, int op, int l, int r) {
if (p == 0) p = ++ tot, tree[p].lazy = op, tree[p].l = l, tree[p].r = r, tree[p].ls = tree[p].rs = tree[p].sum = 0, tree[p].lazy = op;
// cout << l << ' ' << r << ' ' << op;
tree[p].sum = (r - l + 1) * op;
}
void pushlazy(int p) {
if (tree[p].lazy == -1 || tree[p].r == tree[p].l) return;
int mid = tree[p].l + tree[p].r >> 1;
Xg(tree[p].ls, tree[p].lazy, tree[p].l, mid), Xg(tree[p].rs, tree[p].lazy, mid + 1, tree[p].r);
tree[p].lazy = -1;
}
void xg(int &p, int nl, int nr, int l, int r, int op) {
if (nl > r || nr < l || nr < nl) return;
// cout << nl << ' ' << nr << '\n';
if (p == 0) p = ++ tot, tree[p].l = nl, tree[p].r = nr, tree[p].ls = tree[p].rs = tree[p].sum = 0, tree[p].lazy = -1;
pushlazy(p);
if (tree[p].l >= l && tree[p].r <= r) {
Xg(p, op, nl, nr);
return;
}
int mid = nl + nr >> 1;
xg(tree[p].ls, nl, mid, l, r, op);
xg(tree[p].rs, mid + 1, nr, l, r, op);
pushup(p);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> q;
while (q--) {
int l, r, op; cin >> l >> r >> op;
if (op == 1) xg(rt, 1, n, l, r, 1);
else xg(rt, 1, n, l, r, 0);
cout << n - tree[rt].sum << '\n';
}
return 0;
}