#include #include #include #include #include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) using ll = long long; using namespace std; template struct lazy_propagation_segment_tree { // on monoids int n; vector a; vector q; function append_m; // associative function append_q; // associative, not necessarily commutative function apply; // distributive, associative M unit_m; // unit Q unit_q; // unit lazy_propagation_segment_tree() = default; lazy_propagation_segment_tree(int a_n, M a_unit_m, Q a_unit_q, function a_append_m, function a_append_q, function a_apply) { n = pow(2,ceil(log2(a_n))); a.resize(2*n-1, a_unit_m); q.resize(max(0, 2*n-1-n), a_unit_q); unit_m = a_unit_m; unit_q = a_unit_q; append_m = a_append_m; append_q = a_append_q; apply = a_apply; } void range_apply(int l, int r, Q z) { assert (0 <= l and l <= r and r <= n); range_apply(0, 0, n, l, r, z); } void range_apply(int i, int il, int ir, int l, int r, Q z) { if (l <= il and ir <= r) { a[i] = apply(z, a[i]); if (i < q.size()) q[i] = append_q(z, q[i]); } else if (ir <= l or r <= il) { // nop } else { range_apply(2*i+1, il, (il+ir)/2, 0, n, q[i]); range_apply(2*i+1, il, (il+ir)/2, l, r, z); range_apply(2*i+2, (il+ir)/2, ir, 0, n, q[i]); range_apply(2*i+2, (il+ir)/2, ir, l, r, z); a[i] = append_m(a[2*i+1], a[2*i+2]); q[i] = unit_q; } } M range_concat(int l, int r) { assert (0 <= l and l <= r and r <= n); return range_concat(0, 0, n, l, r); } M range_concat(int i, int il, int ir, int l, int r) { if (l <= il and ir <= r) { return a[i]; } else if (ir <= l or r <= il) { return unit_m; } else { return apply(q[i], append_m( range_concat(2*i+1, il, (il+ir)/2, l, r), range_concat(2*i+2, (il+ir)/2, ir, l, r))); } } }; template map coordinate_compression_map(vector const & xs) { int n = xs.size(); vector ys(n); whole(iota, ys, 0); whole(sort, ys, [&](int i, int j) { return xs[i] < xs[j]; }); map f; for (int i : ys) { if (not f.count(xs[i])) { // make unique int j = f.size(); f[xs[i]] = j; // f[xs[i]] has a side effect, increasing the f.size() } } return f; } const ll mod = ll(1e18)+9; struct state_t { ll size; array acc; }; struct query_t { enum { UNIT, LENGTH, FILL } type; ll arg1; int arg2; bool arg3; }; int main() { // input ll n; int q; cin >> n >> q; vector x(q); vector l(q), r(q); repeat (i,q) { cin >> x[i] >> l[i] >> r[i]; ++ r[i]; } // prepare map compress; { vector ps; ps.push_back(0); ps.push_back(n); repeat (i,q) { ps.push_back(l[i]); ps.push_back(r[i]); } compress = coordinate_compression_map(ps); } lazy_propagation_segment_tree segtree(compress[n], (state_t) { 0, {} }, (query_t) { query_t::UNIT }, [&](state_t const & a, state_t const & b) { state_t c; c.size = a.size + b.size; repeat (i,5) c.acc[i] = a.acc[i] + b.acc[i]; return c; }, [&](query_t q, query_t p) { if (q.type == query_t::UNIT) return p; if (p.type == query_t::UNIT) return q; assert (q.type == query_t::FILL); assert (p.type == query_t::FILL); if (q.arg1 == p.arg1) { // if same color if (not q.arg3) { // if not reset q.arg2 += p.arg2; q.arg3 = p.arg3; } } else { q.arg3 = true; // reset } return q; }, [&](query_t p, state_t a) { if (p.type == query_t::UNIT) return a; if (p.type == query_t::LENGTH) return (state_t) { p.arg1, {} }; int color = p.arg1; int depth = p.arg2; bool reset = p.arg3; state_t b = {}; b.size = a.size; b.acc[color] = ((reset ? 0 : a.acc[color]) + depth * a.size % mod) % mod; return b; }); for (auto cur = compress.begin(), nxt = ++ compress.begin(); nxt != compress.end(); ++ cur, ++ nxt) { assert (cur->second + 1 == nxt->second); segtree.range_apply(cur->second, nxt->second, (query_t) { query_t::LENGTH, nxt->first - cur->first }); segtree.range_concat(cur->second, nxt->second); } // solve ll acc[5] = {}; repeat (i,q) { if (x[i] == 0) { state_t it = segtree.range_concat(compress[l[i]], compress[r[i]]); int j = whole(max_element, it.acc) - it.acc.begin(); if (whole(count, it.acc, it.acc[j]) == 1) { acc[j] = (acc[j] + it.acc[j]) % mod; } } else { segtree.range_apply(compress[l[i]], compress[r[i]], (query_t) { query_t::FILL, x[i]-1, 1, false }); } } state_t it = segtree.range_concat(compress[0], compress[n]); repeat (i,5) acc[i] = (acc[i] + it.acc[i]) % mod; // output repeat (i,5) cout << acc[i] << ' '; cout << endl; return 0; }