#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; struct LazySegTree{ int dataSize; vi val, lazy; vector lazyZero; LazySegTree(int n){ dataSize = 1; while(dataSize < n)dataSize *= 2; int treeSize = 2 * dataSize - 1; val = lazy = vi(treeSize); lazyZero = vector(treeSize); } void propagate(int index, int curL, int curR){ // 自分の値をlazyにもとづいて書き換えて自分のlazyをクリア。 // 子のlazyを書き換える。 if(lazyZero[index]){ val[index] = 0; } val[index] += lazy[index] * (curR-curL); if(curR - curL > 1){ int l = index * 2 + 1, r = index * 2 + 2; if(lazyZero[index]){ lazy[l] = lazy[r] = 0; lazyZero[l] = lazyZero[r] = true; } lazy[l] |= lazy[index]; lazy[r] |= lazy[index]; } lazy[index] = 0; lazyZero[index] = false; } // [curL, curR) を評価する void update(int index, int curL, int curR, int givenL, int givenR, bool isAdd){ // 範囲外であろうとpropagateは必ず呼ぶ。そうでないと、親がうまく評価されない propagate(index, curL, curR); // 範囲外 if(curR <= givenL || givenR <= curL)return; // 範囲内 if(givenL <= curL && curR <= givenR){ // 直接書き換えないでindexのlazyを書き換えてpropagateを呼ぶ if(!isAdd){ lazyZero[index] = true; lazy[index] = 0; } else{ lazy[index] |= 1; } propagate(index, curL, curR); } else{ // 範囲外と範囲内が含まれる(長さ2以上) int mid = (curL + curR) / 2; update(index * 2 + 1, curL, mid, givenL, givenR, isAdd); update(index * 2 + 2, mid, curR, givenL, givenR, isAdd); val[index] = val[index * 2 + 1] + val[index * 2 + 2]; } } void update(int l, int r, bool isAdd){ update(0, 0, dataSize, l, r, isAdd); } int query(int l, int r){ return query(0, 0, dataSize, l, r); } int query(int index, int curL, int curR, int givenL, int givenR){ // 範囲外 if(curR <= givenL || givenR <= curL)return 0; propagate(index, curL, curR); if(givenL <= curL && curR <= givenR){ return val[index]; } else{ int mid = (curL + curR) / 2; int res1 = query(index * 2 + 1, curL, mid, givenL, givenR); int res2 = query(index * 2 + 2, mid, curR, givenL, givenR); return res1 + res2; } } }; const int MAX = (int)1e5 + 1; int N, Q, X[MAX], L[MAX], R[MAX]; void solve(){ vll ans(2); vector segTree(2, LazySegTree(N)); rep(i, Q){ R[i]++; X[i]--; if(X[i] == -1){ vll val(2); rep(j, 2)val[j] = segTree[j].query(L[i], R[i]); if(val[0] > val[1])ans[0] += val[0]; else if(val[1] > val[0])ans[1] += val[1]; } else{ segTree[X[i]].update(L[i], R[i], true); segTree[1-X[i]].update(L[i], R[i], false); } } rep(i, 2)ans[i] += segTree[i].query(0, N); cout << ans[0] << ' ' << ans[1] << endl; } int main(){ while(cin >> N >> Q){ rep(i, Q)scanf("%d%d%d", &X[i], &L[i], &R[i]); solve(); } }