using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; using System.Numerics; using System.Text; using static System.Console; using static System.Convert; using static System.Math; using static Extentions; class IO { int idx; string[] input; public IO(TextReader reader) { input = reader.ReadToEnd().Split(new[] { " ", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); } T Get(Func parser) => parser(input[idx++]); public string S => Get(s => s); public char C => Get(char.Parse); public int I => Get(int.Parse); public long L => Get(long.Parse); public double F => Get(double.Parse); public decimal D => Get(decimal.Parse); public BigInteger B => Get(BigInteger.Parse); T[] Gets(int n, Func parser) => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray(); public string[] Ss(int n) => Gets(n, s => s); public char[] Cs(int n) => Gets(n, char.Parse); public int[] Is(int n) => Gets(n, int.Parse); public long[] Ls(int n) => Gets(n, long.Parse); public double[] Fs(int n) => Gets(n, double.Parse); public decimal[] Ds(int n) => Gets(n, decimal.Parse); public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse); public void Write(params T[] xs) => WriteLine(string.Join(" ", xs)); public void Write(params object[] xs) => WriteLine(string.Join(" ", xs)); } static class Extentions { } static class Program { public static void Main() { #if !DEBUG SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false }); #endif Solve(new IO(In)); Out.Flush(); } static void Solve(IO io) { var n = io.I; var m = io.I; var s = (int)Ceiling(Sqrt(n)); var arr = new bool?[n]; var baq = new bool?[s]; var baqlen = n / s + (n % s == 0 ? 0 : 1); var ap = 0; var bp = 0; for (var _ = 0; _ < m; _++) { var q = io.I; var l = io.I; var r = io.I; var baqli = l / s + (l % s == 0 ? 0 : 1); var baqri = (r + 1) / s - 1; if (r == n - 1) baqri = baqlen - 1; if (q == 0) { var tap = 0; var tbp = 0; for (var i = baqli; i <= baqri; i++) { if (baq[i] == null) { var ol = i * s; var or = ol + s - 1; for (var j = ol; j <= or; j++) { if (!arr[j].HasValue) continue; if (arr[j].Value) tap++; else tbp++; } } else if (baq[i].Value) tap += s; else tbp += s; } if (baqli > baqri) { for (var i = l; i <= r; i++) { if (!arr[i].HasValue) continue; if (arr[i].Value) tap++; else tbp++; } goto Count; } if (l % s != 0) { var olr = Min(n - 1, (l / s + (l % s == 0 ? 0 : 1)) * s - 1); for (var i = l; i <= olr; i++) { if (!arr[i].HasValue) continue; if (arr[i].Value) tap++; else tbp++; } } if ((r + 1) % s != 0) { var orl = (r + 1) / s * s; for (var i = orl; i <= r; i++) { if (!arr[i].HasValue) continue; if (arr[i].Value) tap++; else tbp++; } } Count: if (tap > tbp) ap += tap; if (tap < tbp) bp += tbp; continue; } for (var i = baqli; i <= baqri; i++) baq[i] = q == 1; if (l % s != 0) { if (baq[baqli - 1] != null) { var ol = (baqli - 1) * s; var or = Min(n - 1, ol + s - 1); for (var i = ol; i <= or; i++) arr[i] = baq[baqli - 1].Value; baq[baqli - 1] = null; } var olr = Min(n - 1, (l / s + (l % s == 0 ? 0 : 1)) * s - 1); for (var i = l; i <= olr; i++) arr[i] = q == 1; } if ((r + 1) % s != 0) { if (baq[baqri + 1] != null) { var ol = (baqri + 1) * s; var or = Min(n - 1, ol + s - 1); for (var i = ol; i <= or; i++) arr[i] = baq[baqri + 1].Value; baq[baqri + 1] = null; } var orl = (r + 1) / s * s; for (var i = orl; i <= r; i++) arr[i] = q == 1; } } for (var i = 0; i < baqlen; i++) { if (baq[i] == null) { var ol = i * s; var or = Min(n - 1, ol + s - 1); for (var j = ol; j <= or; j++) { if (!arr[j].HasValue) continue; if (arr[j].Value) ap++; else bp++; } } else if (baq[i].Value) ap += s; else bp += i == baqlen - 1 ? n - s * (baqlen - 1) : s; } io.Write(ap, bp); } }