using System; using System.IO; using System.Linq; using System.Text; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; class Program { public void Solve() { int N = Reader.Int(), Q = Reader.Int(); var Qs = Reader.IntTable(Q); var A = new RangeUpdateSegTree(N); var B = new RangeUpdateSegTree(N); long scoreA = 0, scoreB = 0; for (int qi = 0; qi < Q; qi++) { var q = Qs[qi]; int L = q[1], R = q[2] + 1; if (q[0] == 0) { int countA = A.Sum(L, R); int countB = B.Sum(L, R); if (countA > countB) scoreA += countA; if (countB > countA) scoreB += countB; } else if (q[0] == 1) { A.Update(L, R, 1); B.Update(L, R, 0); } else { B.Update(L, R, 1); A.Update(L, R, 0); } } scoreA += A.Sum(0, N); scoreB += B.Sum(0, N); Console.WriteLine(scoreA + " " + scoreB); } class RangeUpdateSegTree { public readonly int N; private readonly int[] V, S; private readonly bool[] Flag; public RangeUpdateSegTree(int n) { for (N = 4; N < n; ) N *= 2; V = new int[N * 2]; S = new int[N * 2]; Flag = new bool[N * 2]; } public int Sum(int L, int R) { return Sum(0, 0, N, L, R); } private int Sum(int i, int currL, int currR, int L, int R) { if (currL >= R || currR <= L) return 0; if (currL >= L && currR <= R) return S[i]; if (Flag[i]) return V[i] * (Math.Min(currR, R) - Math.Max(currL, L)); int mid = (currL + currR) / 2; int valL = Sum(i * 2 + 1, currL, mid, L, R); int valR = Sum(i * 2 + 2, mid, currR, L, R); return valL + valR; } public void Update(int L, int R, int val) { Update(0, val, 0, N, L, R); } private void Update(int i, int val, int currL, int currR, int L, int R) { if (currL >= R || currR <= L) return; if (currL >= L && currR <= R) { Flag[i] = true; V[i] = val; S[i] = val * (currR - currL); return; } if (Flag[i] && currR - currL > 1) { V[i * 2 + 1] = V[i * 2 + 2] = V[i]; S[i * 2 + 1] = S[i * 2 + 2] = (currR - currL) / 2 * V[i]; Flag[i * 2 + 1] = Flag[i * 2 + 2] = true; Flag[i] = false; } int mid = (currL + currR) / 2; Update(i * 2 + 1, val, currL, mid, L, R); Update(i * 2 + 2, val, mid, currR, L, R); S[i] = S[i * 2 + 1] + S[i * 2 + 2]; } } } class Entry { static void Main() { new Program().Solve(); } } class Reader { private static TextReader reader = Console.In; private static readonly char[] separator = { ' ' }; private static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; private static string[] A = new string[0]; private static int i; private static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); } public static int[][] IntTable(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); } public static string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); } public static string Line() { return reader.ReadLine().Trim(); } private static string[] Split(string s) { return s.Split(separator, op); } private static string Next() { CheckNext(); return A[i++]; } private static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }