import std.conv, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken().to!int; } long readLong() { return readToken().to!long; } real readReal() { return readToken().to!real; } void chmin(T)(ref T t, in T f) { if (t > f) t = f; } void chmax(T)(ref T t, in T f) { if (t < f) t = f; } int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; } int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); } int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); } immutable MO = 10L^^18 + 9; immutable NUM_COLORS = 5; class SegmentTree { int n; long[] xs; long[][] sum; Tuple!(int, "color", long, "thick")[] add; this(int n_, long[] xs_) { for (n = 1; n < n_; n <<= 1) {} xs = new long[n << 1]; xs[0 .. n_ + 1] = xs_[]; xs[n_ + 1 .. $] = xs[n_]; sum = new long[][](n << 1, NUM_COLORS); add.length = n << 1; add[] = tuple!("color", "thick")(-1, 0L); } private void fill(int u, int l, int r, int col, long thk) { foreach (c; 0 .. NUM_COLORS) { if (c == col) { sum[u][c] += (xs[r] - xs[l]) * thk; } else { sum[u][c] = 0; } } if (add[u].color != col) { add[u] = tuple!("c", "thick")(col, 0L); } add[u].thick += thk; } private long[] query(int u, int l, int r, int a, int b, int col, long thk) { chmax(a, l); chmin(b, r); if (a >= b) { return new long[NUM_COLORS]; } if (a == l && b == r) { if (col != -1) { fill(u, l, r, col, thk); } return sum[u]; } const uL = u << 1; const uR = u << 1 | 1; const mid = (l + r) >> 1; if (add[u].color != -1) { fill(uL, l, mid, add[u].color, add[u].thick); fill(uR, mid, r, add[u].color, add[u].thick); add[u] = tuple!("color", "thick")(-1, 0L); } const resL = query(uL, l, mid, a, b, col, thk); const resR = query(uR, mid, r, a, b, col, thk); auto ret = new long[NUM_COLORS]; foreach (c; 0 .. NUM_COLORS) { sum[u][c] = sum[uL][c] + sum[uR][c]; ret[c] = resL[c] + resR[c]; } return ret; } long[] query(int a, int b, int col, long thk) { return query(1, 0, n, a, b + 1, col, thk); } } long N; int Q; int[] X; long[] L, R; void main() { try { for (; ; ) { N = readLong(); Q = readInt(); X = new int[Q]; L = new long[Q]; R = new long[Q]; foreach (q; 0 .. Q) { X[q] = readInt() - 1; L[q] = readLong(); R[q] = readLong(); } long[] xs; xs ~= 0; xs ~= N; foreach (q; 0 .. Q) { xs ~= L[q]; xs ~= R[q] + 1; } xs = xs.sort.uniq.array; const xsLen = cast(int)(xs.length) - 1; debug { writeln("xsLen = ", xsLen); writeln("xs = ", xs); } auto ans = new long[NUM_COLORS]; auto seg = new SegmentTree(xsLen, xs); foreach (q; 0 .. Q) { const a = xs.lowerBound(L[q]); const b = xs.lowerBound(R[q] + 1) - 1; const res = seg.query(a, b, X[q], 1); if (X[q] == -1) { // TODO: bonus const mx = res.maxElement; if (res.count(mx) == 1) { (ans[res.maxIndex] += mx) %= MO; } } } { const res = seg.query(0, xsLen - 1, -1, 0); foreach (c; 0 .. NUM_COLORS) { (ans[c] += res[c]) %= MO; } } writeln(ans.to!string.replaceAll(regex(`[\[\],]`), "")); } } catch (EOFException e) { } }