#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; typedef complex C; enum class color {mine, yours, invalid}; const int MAXN = (1<<17); struct SegTreeLazy { vector val; vector lazy; SegTreeLazy() {val.resize(2*MAXN); lazy.resize(2*MAXN, color::invalid);} int get(int x, int y, int l = 0, int r = MAXN, int k = 1) { if (r <= x || y <= l) return 0; if (x <= l && r <= y) return val[k]; x = max(x, l); y = min(y, r); if (lazy[k] != color::invalid) { if (lazy[k] == color::mine) return y-x; else return 0; } return get(x, y, l, (l+r)/2, 2*k) + get(x, y, (l+r)/2, r, 2*k+1); } void update(int x, int y, color col, int l = 0, int r = MAXN, int k = 1) { if (l >= r) return; if (x <= l && r <= y) { lazy[k] = col; val[k] = lazy[k] != color::yours ? (r-l) : 0; } else if (l < y && x < r) { if (lazy[k] != color::invalid) { lazy[k*2] = lazy[k*2+1] = lazy[k]; val[k*2] = val[k*2+1] = lazy[k] != color::yours ? (r-l)/2 : 0; lazy[k] = color::invalid; } update(x, y, col, l, (l+r)/2, k*2); update(x, y, col, (l+r)/2, r, k*2+1); val[k] = val[k*2] + val[k*2+1]; } } }; SegTreeLazy seg[2]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, Q; cin >> N; cin >> Q; ll A = 0, B = 0; while (Q--) { int x, l, r; cin >> x >> l >> r; if (x == 0) { int a = seg[0].get(l, r+1); int b = seg[1].get(l, r+1); if (a < b) B += b; else if (a > b) A += a; } else if (x == 1) { seg[0].update(l, r+1, color::mine); seg[1].update(l, r+1, color::yours); } else { seg[1].update(l, r+1, color::mine); seg[0].update(l, r+1, color::yours); } } A += seg[0].get(0, N+1); B += seg[1].get(0, N+1); cout << A << " " << B << endl; return 0; }