class LazySegTree: def __init__(self, init_val, seg_ide, lazy_ide, f, g, h): self.n = len(init_val) self.num = 2**(self.n-1).bit_length() self.seg_ide = seg_ide self.lazy_ide = lazy_ide self.f = f self.g = g self.h = h self.seg = [seg_ide]*2*self.num for i in range(self.n): self.seg[i+self.num] = init_val[i] for i in range(self.num-1, 0, -1): self.seg[i] = self.f(self.seg[2*i], self.seg[2*i+1]) self.size = [0]*2*self.num for i in range(self.n): self.size[i+self.num] = 1 for i in range(self.num-1, 0, -1): self.size[i] = self.size[2*i] + self.size[2*i+1] self.lazy = [lazy_ide]*2*self.num def update(self, i, x): i += self.num self.seg[i] = x while i: i = i >> 1 self.seg[i] = self.f(self.seg[2*i], self.seg[2*i+1]) def calc(self, i): return self.g(self.seg[i], self.lazy[i], self.size[i]) def calc_above(self, i): i = i >> 1 while i: self.seg[i] = self.f(self.calc(2*i), self.calc(2*i+1)) i = i >> 1 def propagate(self, i): self.seg[i] = self.g(self.seg[i], self.lazy[i], self.size[i]) self.lazy[2*i] = self.h(self.lazy[2*i], self.lazy[i]) self.lazy[2*i+1] = self.h(self.lazy[2*i+1], self.lazy[i]) self.lazy[i] = self.lazy_ide def propagate_above(self, i): H = i.bit_length() for h in range(H, 0, -1): self.propagate(i >> h) def query(self, l, r): l += self.num r += self.num lm = l // (l & -l) rm = r // (r & -r) -1 self.propagate_above(lm) self.propagate_above(rm) al = self.seg_ide ar = self.seg_ide while l < r: if l & 1: al = self.f(al, self.calc(l)) l += 1 if r & 1: r -= 1 ar = self.f(self.calc(r), ar) l = l >> 1 r = r >> 1 return self.f(al, ar) def oprerate_range(self, l, r, a): l += self.num r += self.num lm = l // (l & -l) rm = r // (r & -r) -1 self.propagate_above(lm) self.propagate_above(rm) while l < r: if l & 1: self.lazy[l] = self.h(self.lazy[l], a) l += 1 if r & 1: r -= 1 self.lazy[r] = self.h(self.lazy[r], a) l = l >> 1 r = r >> 1 self.calc_above(lm) self.calc_above(rm) def __str__(self): # for debug arr = [self.query(i,i+1) for i in range(self.n)] return str(arr) f = lambda x, y: x+y g = lambda x, a, s: a*s if a is not None else x h = lambda a, b: b if b is not None else a import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): n = int(input()) q = int(input()) sa = 0 sb = 0 segA = LazySegTree([0]*n, 0, None, f, g, h) segB = LazySegTree([0]*n, 0, None, f, g, h) for i in range(q): x, l, r = map(int, input().split()) if x == 0: ca = segA.query(l, r+1) cb = segB.query(l, r+1) if ca > cb: sa += ca elif ca < cb: sb += cb elif x == 1: segA.oprerate_range(l, r+1, 1) segB.oprerate_range(l, r+1, 0) else: segA.oprerate_range(l, r+1, 0) segB.oprerate_range(l, r+1, 1) sa += segA.query(0, segA.n) sb += segB.query(0, segB.n) print(sa, sb) if __name__ == '__main__': main()