#include #include #include using namespace std; typedef long long ll; enum class color { mine, yours, invalid }; template struct lazy_segtree { vector val; // 確定値 vector lazy; // 遅延値(自分の色かどうか: Mine, Yours or 塗りつぶしが一様でない: Invalid) lazy_segtree() { val.resize(Max*2); lazy.resize(Max*2, color::invalid); } int get(int x, int y, int l=0, int r=Max, 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) { return lazy[k] == color::mine ? (y-x) : 0; } return get(x, y, l, (l+r)/2, k*2) + get(x, y, (l+r)/2, r, k*2+1); } void update(int x, int y, color col, int l=0, int r=Max, 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]; } } }; int N, Q; ll AA, BB; lazy_segtree<1<<20> st[2]; int main() { cin >> N >> Q; while(Q--) { int x, l, r; cin >> x >> l >> r; if(x == 0) { int a = st[0].get(l, r+1); int b = st[1].get(l, r+1); if(a > b) { AA += a; } if(a < b) { BB += b; } } else { st[x-1].update(l, r+1, color::mine); st[(x-1)^1].update(l, r+1, color::yours); } } AA += st[0].get(0, N); BB += st[1].get(0, N); cout << AA << " " << BB << endl; return 0; }