#include using namespace std; struct RSQ { // RMQ (3 level decomposition) static const int S = 47; struct Tuple { int sum; int lazy = -1; }; Tuple L1[S], L2[S * S], L3[S * S * S]; void push(int k) { int b = k / S / S; if (L1[b].lazy != -1) { for (int i = b * S; i < b * S + S; i++) { L2[i].lazy = L1[b].lazy; L2[i].sum = L1[b].lazy * S * S; } L1[b].lazy = -1; } b = k / S; if (L2[b].lazy != -1) { for (int i = b * S; i < b * S + S; i++) { L3[i].sum = L2[b].lazy * S; } L2[b].lazy = -1; } } void fill(int l, int r, bool k) { push(l); push(r - 1); while (l < r && l % S != 0) L3[l++].sum = k; while (l < r && r % S != 0) L3[--r].sum = k; l /= S; r /= S; while (l < r && l % S != 0) { L2[l].sum = k * S; L2[l].lazy = k; l++; } while (l < r && r % S != 0) { r--; L2[r].sum = k * S; L2[l].lazy = k; } while (l < r) { L3[l].sum = k * S * S; L3[l].lazy = k; l++; } } int query(int l, int r) { push(l); push(r - 1); int ret = 0; while (l < r && l % S != 0) ret += L3[l++].sum; while (l < r && r % S != 0) ret += L3[--r].sum; l /= S; r /= S; while (l < r && l % S != 0) ret += L2[l++].sum; while (l < r && r % S != 0) ret += L2[--r].sum; l /= S; r /= S; while (l < r) ret += L1[l++].sum; return ret; } }; RSQ rsq[2]; int main() { int n, q; cin >> n >> q; long long scoreA = 0; long long scoreB = 0; while (q--) { int x, l, r; scanf("%d %d %d", &x, &l, &r); x--; r++; if (x == -1) { int a = rsq[0].query(l, r); int b = rsq[1].query(l, r); if (a > b) scoreA += a; if (a < b) scoreB += b; } else { rsq[x].fill(l, r, 1); rsq[x ^ 1].fill(l, r, 0); } } scoreA += rsq[0].query(0, n); scoreB += rsq[1].query(0, n); cout << scoreA << " " << scoreB << endl; }