#define YRSD #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define TE template #define TES template #define Z auto #define ep emplace_back #define eb emplace #define fi first #define se second #define bg begin #define ed end #define all(x) bg(x), ed(x) #define ov(a, b, c, d, e, ...) e #define FO1(a) for (int _ = 0; _ < (a); ++_) #define FO2(i, a) for (int i = 0; i < (a); ++i) #define FO3(i, a, b) for (int i = (a); i < (b); ++i) #define FO4(i, a, b, c) for (int i = (a); i < (b); i += (c)) #define FOR(...) ov(__VA_ARGS__, FO4, FO3, FO2, FO1)(__VA_ARGS__) #define FF1(a) for (int _ = (a) - 1; _ >= 0; --_) #define FF2(i, a) for (int i = (a) - 1; i >= 0; --i) #define FF3(i, a, b) for (int i = (b) - 1; i >= (a); --i) #define FF4(i, a, b, c) for (int i = (b) - 1; i >= (a); i -= (c)) #define FOR_R(...) ov(__VA_ARGS__, FF4, FF3, FF2, FF1)(__VA_ARGS__) #define FOR_subset(t, s) for (int t = (s); t > -1; t = (t == 0 ? -1 : (t - 1) & s)) #define sort ranges::sort using namespace std; TE using vc = vector; TE using vvc = vc>; TE using T1 = tuple; TE using T2 = tuple; TE using T3 = tuple; TE using T4 = tuple; TE using max_heap = priority_queue; TE using min_heap = priority_queue, greater>; using u8 = unsigned char; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using ld = long double; using i128 = __int128; using u128 = __uint128_t; using f128 = __float128; using u16 = uint16_t; using PII = pair; using PLL = pair; #ifdef YRSD constexpr bool dbg = 1; #else constexpr bool dbg = 0; #endif istream &operator>>(istream &I, i128 &x) { static string s; I >> s; int f = s[0] == '-'; x = 0; const int N = (int)s.size(); FOR(i, f, N) x = x * 10 + s[i] - '0'; if (f) x = -x; return I; } ostream &operator<<(ostream &O, i128 x) { static string s; s.clear(); bool f = x < 0; if (f) x = -x; while (x) s += '0' + x % 10, x /= 10; if (s.empty()) s += '0'; if (f) s += '-'; reverse(all(s)); return O << s; } istream &operator>>(istream &I, f128 &x) { static string s; I >> s, x = stold(s); return I; } ostream &operator<<(ostream &O, const f128 x) { return O << ld(x); } template istream &operator>>(istream &I, tuple &t) { return apply([&I](Z &...s) { ((I >> s), ...); }, t), I; } template istream &operator>>(istream &I, pair &x) { return I >> x.fi >> x.se; } template ostream &operator<<(ostream &O, const pair &x) { return O << x.fi << ' ' << x.se; } TE requires requires(T &c) { begin(c); end(c); } and (not is_same_v, string>) istream &operator>>(istream &I, T &c) { for (Z &e : c) I >> e; return I; } TE requires requires(const T &c) { begin(c); end(c); } and (not is_same_v, const char*>) and (not is_same_v, string>) and (not is_array_v> or not is_same_v>, char>) ostream &operator<<(ostream &O, const T &a) { if (a.empty()) return O; Z i = a.begin(); O << *i++; for (; i != a.end(); ++i) O << ' ' << *i; return O; } void IN() {} TE void IN(T &x, Z &...s) { cin >> x, IN(s...); } void print() { cout << '\n'; } TES void print(T &&x, S &&...y) { cout << x; if constexpr (sizeof...(S)) cout << ' '; print(forward(y)...); } void put() {} TES void put(T &&x, S &&...y) { cout << x; put(forward(y)...); } #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define UINT(...) uint __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define ULL(...) ull __VA_ARGS__; IN(__VA_ARGS__) #define I128(...) i128 __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define CH(...) char __VA_ARGS__; IN(__VA_ARGS__) #define REAL(...) re __VA_ARGS__; IN(__VA_ARGS__) #define VEC(T, a, n) vc a(n); IN(a) void YES(bool o = 1) { print(o ? "YES" : "NO"); } void Yes(bool o = 1) { print(o ? "Yes" : "No"); } void yes(bool o = 1) { print(o ? "yes" : "no"); } void NO(bool o = 1) { YES(not o); } void No(bool o = 1) { Yes(not o); } void no(bool o = 1) { yes(not o); } void ALICE(bool o = 1) { print(o ? "ALICE" : "BOB"); } void Alice(bool o = 1) { print(o ? "Alice" : "Bob"); } void alice(bool o = 1) { print(o ? "alice" : "bob"); } void BOB(bool o = 1) { ALICE(not o); } void Bob(bool o = 1) { Alice(not o); } void bob(bool o = 1) { alice(not o); } void POSSIBLE(bool o = 1) { print(o ? "POSSIBLE" : "IMPOSSIBLE"); } void Possible(bool o = 1) { print(o ? "Possible" : "Impossible"); } void possible(bool o = 1) { print(o ? "possible" : "impossible"); } void IMPOSSIBLE(bool o = 1) { POSSIBLE(not o); } void Impossible(bool o = 1) { Possible(not o); } void impossible(bool o = 1) { possible(not o); } void TAK(bool o = 1) { print(o ? "TAK" : "NIE"); } void NIE(bool o = 1) { TAK(not o); } #if (__cplusplus >= 202002L) #include constexpr ld pi = numbers::pi_v; #endif TE constexpr T inf = numeric_limits::max(); template <> constexpr i128 inf = i128(inf) * 2'000'000'000'000'000'000; template constexpr pair inf> = {inf, inf}; TE constexpr static inline int pc(T x) { return popcount(make_unsigned_t(x)); } constexpr static inline ll len(const Z &a) { return a.size(); } void reverse(Z &a) { reverse(all(a)); } void unique(Z &a) { sort(a); a.erase(unique(all(a)), a.end()); } TE vc inverse(const vc &a) { int N = len(a); vc b(N, -1); FOR(i, N) if (a[i] != -1) b[a[i]] = i; return b; } Z QMAX(const Z &a) { return *max_element(all(a)); } Z QMIN(const Z &a) { return *min_element(all(a)); } TE Z QMAX(T l, T r) { return *max_element(l, r); } TE Z QMIN(T l, T r) { return *min_element(l, r); } constexpr bool chmax(Z &a, const Z &b) { return (a < b ? a = b, 1 : 0); } constexpr bool chmin(Z &a, const Z &b) { return (a > b ? a = b, 1 : 0); } vc argsort(const Z &a) { vc I(len(a)); iota(all(I), 0); sort(I, [&](int i, int k) { return a[i] < a[k] or (a[i] == a[k] and i < k); }); return I; } TE vc rearrange(const vc &a, const vc &I) { int N = len(I); vc b(N); FOR(i, N) b[i] = a[I[i]]; return b; } template vc pre_sum(const vc &a) { int N = len(a); vc c(N + 1); FOR(i, N) c[i + 1] = c[i] + a[i]; if (of == 0) c.erase(c.begin()); return c; } TE constexpr static int topbit(T x) { if (x == 0) return - 1; if constexpr (sizeof(T) <= 4) return 31 - __builtin_clz(x); else return 63 - __builtin_clzll(x); } TE constexpr static int lowbit(T x) { if (x == 0) return -1; if constexpr (sizeof(T) <= 4) return __builtin_ctz(x); else return __builtin_ctzll(x); } TE constexpr T floor(T x, T y) { return x / y - (x % y and (x ^ y) < 0); } TE constexpr T ceil(T x, T y) { return floor(x + y - 1, y); } TE constexpr T bmod(T x, T y) { return x - floor(x, y) * y; } TE constexpr pair divmod(T x, T y) { T q = floor(x, y); return pair{q, x - q * y}; } TE T SUM(const Z &v) { return accumulate(all(v), T()); } TE T SUM(Z l, Z r) { return accumulate(l, r, T()); } int lb(const Z &a, Z x) { return lower_bound(all(a), x) - a.begin(); } TE int lb(T l, T r, Z x) { return lower_bound(l, r, x) - l; } int ub(const Z &a, Z x) { return upper_bound(all(a), x) - a.begin(); } TE int ub(T l, T r, Z x) { return upper_bound(l, r, x) - l; } template ll bina(Z f, ll l, ll r) { if (ck) assert(f(l)); while (abs(l - r) > 1) { ll x = (r + l) >> 1; (f(x) ? l : r) = x; } return l; } TE T bina_real(Z f, T l, T r, int c = 100) { while (c--) { T x = (l + r) / 2; (f(x) ? l : r) = x; } return (l + r) / 2; } Z pop(Z &s) { if constexpr (requires { s.pop_back(); }) { Z x = s.back(); return s.pop_back(), x; } else if constexpr (requires { s.top(); }) { Z x = s.top(); return s.pop(), x; } else { Z x = s.front(); return s.pop(), x; } } void setp(int x) { cout << fixed << setprecision(x); } TE inline void sh(vc &a, int N, T b = {}) { a.resize(N, b); } #ifdef YRSD void DBG() { cerr << "]" << endl; } TES void DBG(T &&x, S &&...y) { cerr << x; if constexpr (sizeof...(S)) cerr << ", "; DBG(forward(y)...); } #define debug(...) cerr << "[" << __LINE__ << "]: [" #__VA_ARGS__ "] = [", DBG(__VA_ARGS__) void ERR() { cerr << endl; } TES void ERR(T &&x, S &&...y) { cerr << x; if constexpr (sizeof...(S)) cerr << ", "; ERR(forward(y)...); } #define err(...) cerr << "[" << __LINE__ << "]: ", ERR(__VA_ARGS__) #else #define debug(...) void(0721) #define err(...) void(0721) #endif template struct node_pool { using np = T*; union U { U *nx; alignas(T) u8 nd[sizeof(T)]; }; vc a, b; U *l = 0, *r = 0, *h = 0; node_pool() { add(); } ~node_pool() { re(); } void reserve(int x) { int t = (x + sz - 1) / sz, n = len(b) + len(a); FOR(i, t, n) a.ep(new U[sz]); } template np gen(S&&...x) { U* s = ac(); return ::new(&s->nd) T{std::forward(x)...}; } np cl(np x) { if (not x) return x; return gen(*x); } void del(np x) { if (not x) return ; x->~T(); U* s = reinterpret_cast(x); s->nx = h, h = s; } void reset() { h = 0, re(), add(); } U* ac() { if (h) { U* s = h; return h = h->nx, s; } if (l == r) add(); return l++; } void add() { U* x; if (not a.empty()) x = pop(a); else x = new U[sz]; b.ep(x), l = x, r = x + sz; } void re() { if (not b.empty()) { for (Z x : b) delete[] x; b.clear(); } if (not a.empty()) { for (Z x : a) delete[] x; a.clear(); } l = r = 0; } }; template struct node_pool_sim { using np = T*; union U { U *nx; alignas(T) u8 nd[sizeof(T)]; }; vc a; U *l = 0, *r = 0; node_pool_sim() { add(); } ~node_pool_sim() { for (Z x : a) delete[] x; } template np gen(S &&...x) { U *s = ac(); return ::new(&s->nd) T(std::forward(x)...); } U *ac() { if (l == r) add(); return l++; } void add() { U* x = new U[sz]; a.ep(x), l = x, r = x + sz; } }; template struct segdl_t { using AM = am; using MX = AM::MX; using MA = AM::MA; using X = MX::X; using A = MA::X; struct node { node *l, *r; X x; A f; void upd() { x = l ? l->x : MX::unit(); if (r) x = MX::op(x, r->x); } }; using np = node*; node_pool a; ll L, R; segdl_t(ll l, ll r) : L(l), R(r) {} ~segdl_t() { a.reset(); } np newnode() { return newnode(MX::unit()); } np newnode(X x) { return a.gen(nullptr, nullptr, x, MA::unit()); } np newnode(np l, np r) { np t = a.gen(l, r, MX::unit(), MA::unit()); return t->upd(), t; } np newnode(const vc &a) { Z f = [&](Z &f, int l, int r) -> np { if (l == r) return 0; if (l + 1 == r) return newnode(a[l]); int m = (l + r) >> 1; return newnode(f(f, l, m), f(f, m, r)); }; return f(f, 0, len(a)); } np cl(np x) { if (not persistent or not x) return x; return a.cl(x); } void push(np x, ll l, ll r) { if (x->f == MA::unit()) return; ll m = (l + r) >> 1; x->l = x->l ? cl(x->l) : newnode(); x->l->x = AM::act(x->l->x, x->f, m - l); x->l->f = MA::op(x->l->f, x->f); x->r = x->r ? cl(x->r) : newnode(); x->r->x = AM::act(x->r->x, x->f, r - m); x->r->f = MA::op(x->r->f, x->f); x->f = MA::unit(); } vc get_all(np x) { vc s; Z f = [&](Z &f, np x, ll l, ll r, A a) -> void { if (not x) return; if (l + 1 == r) return s.ep(AM::act(x->x, a, l, r)), void(); ll m = (l + r) >> 1; a = MA::op(x->f, a); f(f, x->l, l, m, a), f(f, x->r, m, r, a); }; return f(f, x, L, R, MA::unit()), s; } void reset() { a.reset(); } X prod(np x, ll l, ll r) { if (l == r or not x) return MX::unit(); return _p(x, L, R, l, r, MA::unit()); } X _p(np x, ll l, ll r, ll ql, ll qr, A f) { chmax(ql, l), chmin(qr, r); if (ql >= qr) return MX::unit(); if (not x) return AM::act(MX::unit(), f, qr - ql); if (l == ql and r == qr) return AM::act(x->x, f, r - l); ll m = (l + r) >> 1; f = MA::op(x->f, f); return MX::op(_p(x->l, l, m, ql, qr, f), _p(x->r, m, r, ql, qr, f)); } np set(np x, ll i, const X &w) { if (not x) x = newnode(); return _s(x, L, R, i, w); } np _s(np x, ll l, ll r, ll i, const X &w, bool cp = 1) { if (l + 1 == r) { if (cp) { if (cp) x = cl(x); return x->x = w, x->f = MA::unit(), x; } } push(x, l, r); ll m = (l + r) >> 1; bool f = 1; x = cl(x); if (i < m) { if (not x->l) x->l = newnode(), f = 0; x->l = _s(x->l, l, m, i, w, f); } else { if (not x->r) x->r = newnode(), f = 0; x->r = _s(x->r, m, r, i, w, f); } return x->upd(), x; } np multiply(np x, ll i, const X &w) { if (not x) x = newnode(); return _m(x, L, R, i, w); } np _m(np x, ll l, ll r, ll i, const X &w, bool cp = 1) { if (l + 1 == r) { if (cp) x = cl(x); return x->x = MX::op(x->x, w), x->f = MA::unit(), x; } push(x, l, r); ll m = (l + r) >> 1; if (cp) x = cl(x); bool f = 1; if (i < m) { if (not x->l) x->l = newnode(), f = 0; x->l = _m(x->l, l, m, i, w, f); } else { if (not x->r) x->r = newnode(), f = 0; x->r = _m(x->r, m, r, i, w, f); } return x->upd(), x; } np apply(np x, ll l, ll r, const A &f) { if (l == r) return x; return _a(x, L, R, l, r, f); } np _a(np x, ll l, ll r, ll ql, ll qr, const A &f) { if (not x) x = newnode(); chmax(ql, l), chmin(qr, r); if (ql >= qr) return x; if (l == ql and r == qr) return x = cl(x), x->x = AM::act(x->x, f, r - l), x->f = MA::op(x->f, f), x; push(x, l, r); ll m = (l + r) >> 1; x = cl(x); x->l = _a(x->l, l, m, ql, qr, f), x->r = _a(x->r, m, r, ql, qr, f); return x->upd(), x; } ll max_right(np x, const Z &f, ll l) { X w = MX::unit(); return _max_r(x, f, L, R, l, w); } ll _max_r(np x, const Z &f, ll l, ll r, ll ql, X &w) { if (r <= ql) return r; X pr = x ? x->x : MX::unit(); if (ql <= l and f(MX::op(w, pr))) return w = MX::op(w, pr), R; if (l + 1 == r) return l; push(x, l, r); ll m = (l + r) >> 1, k = _max_r(x ? x->l : x, f, l, m, ql, w); if (k != R) return k; return _max_r(x ? x->r : x, f, m, r, ql, w); } ll min_left(np x, const Z &f, ll l) { X w = MX::unit(); return _min_l(x, f, L, R, l, w); } ll _min_l(np x, const Z &f, ll l, ll r, ll qr, X &w) { if (qr <= l) return L; X pr = x ? x->x : MX::unit(); if (r <= qr and f(MX::op(pr, w))) return w = MX::op(pr, w), L; if (l + 1 == r) return r; push(x, l, r); ll m = (l + 1) >> 1, k = _min_l(x ? x->r : x, f, m, r, qr, w); if (k != L) return k; return _min_l(x ? x->l : x, l, m, qr, w); } np copy(np x, np y, ll l, ll r, A f = MA::unit()) { if (x == y) return x; x = cl(x); _copy(x, y, L, R, l, r, f); return x; } void _copy(np x, np y, ll l, ll r, ll ql, ll qr, A f) { chmax(ql, l), chmin(qr, r); if (ql >= qr) return; if (l == ql and r == qr) { if (y) *x = {y->l, y->r, AM::act(y->x, f, r - l), MA::op(y->f, f)}; else *x = {0, 0, AM::act(MX::unit(), f, r - l), f}; return; } push(x, l, r); if (y) f = MA::op(y->f, f); ll m = (l + r) >> 1; x->l = x->l ? cl(x->l) : newnode(); x->r = x->r ? cl(x->r) : newnode(); _copy(x->l, y ? y->l : y, l, m, ql, qr, f); _copy(x->r, y ? y->r : y, m, r, ql, qr, f); x->upd(); } np merge_to(np x, np y, const Z &op, A f = MA::unit()) { return _merge_to(x, y, L, R, op, f); } np _merge_to(np x, np y, ll l, ll r, const Z &op, A f) { if (not x) return y; if (not y) return x; np re = x; if (l + 1 == r) return re->x = op(x->x, y->x), re->f = MA::unit(), re; push(x, l, r); ll m = (l + r) >> 1; f = MA::op(y->f, f); re->l = _merge_to(x->l, y->l, l, m, op, f); re->r = _merge_to(x->r, y->r, m, r, op, f); return re->upd(), a.del(y), re; } np merge_new(np x, np y, const Z &op, A f = MA::unit()) { return _merge_new(x, y, L, R, op, f); } np _merge_new(np x, np y, ll l, ll r, const Z &op, A f) { if (not x) return y; if (not y) return x; np re = newnode(); if (l + 1 == r) return re->x = op(x->x, y->x), re->f = MA::unit(), re; ll m = (l + r) >> 1; f = MA::op(x->f, f); re->l = _merge_new(x->l, y->l, l, m, op, f); re->r = _merge_new(x->r, y->r, m, r, op, f); return re->upd(), re; } np spl(np x, np &y, ll l, ll r, A f = MA::unit()) { if (not x and y) x = newnode(); return _spl(x, y, L, R, l, r, f), x; } void _spl(np &x, np &y, ll l, ll r, ll ql, ll qr, A f = MA::unit()) { if (not y) return; chmax(ql, l), chmin(qr, r); if (ql >= qr) return; if (l == ql and r == qr) { x = y; y = 0; return; } if (not x) x = newnode(); ll m = (l + r) >> 1; f = MA::op(y->f, f); _spl(x->l, y->l, l, m, ql, qr, f); _spl(x->r, y->r, m, r, ql, qr, f); x->upd(); if (not y) return; if (not y->l and not y->r) y = 0; else y->upd(); } }; TE struct monoid_add { using X = T; static constexpr inline X op(const X &x, const X &y) { return x + y; } static constexpr inline X inv(const X &x) { return -x; } static constexpr inline X pow(const X &x, ll n) { return X(n) * x; } static constexpr inline X unit() { return X(0); } static constexpr bool commute = 1; }; TE struct monoid_affine { struct X { T a, b; T eval(T x) const { return a * x + b; } bool operator==(const X &p) const { return a == p.a and b == p.b; } bool operator!=(const X &p) const { return a != p.a or b != p.b; } }; static constexpr X op(const X &f, const X &g) { return {f.a * g.a, f.b * g.a + g.b}; } static constexpr X inv(const X &x) { Z [a, b] = x; a = T(1) / a; return {a, a * -b}; } static constexpr X unit() { return {T(1), T(0)}; } static constexpr X make_add(T x) { return {T(1), x}; } static constexpr X make_mul(T x) { return {T(x), T(0)}; } static constexpr bool commute = 0; }; TE struct a_monoid_sum_affine { using MX = monoid_add; using MA = monoid_affine; using X = MX::X; using A = MA::X; static constexpr X act(const X &x, const A &a, ll sz) { return x * a.a + T(sz) * a.b; } }; using AM = a_monoid_sum_affine; using MX = AM::MX; using MA = AM::MA; using DS = segdl_t; using np = DS::np; constexpr ull mod = 1'000'000'000'000'000'000ull + 9; void Yorisou() { LL(N, Q); DS seg(0, N); np t[5]{}; array s{}; FOR(Q) { LL(x, l, r); ++r; if (x == 0) { ull g[5]{}; FOR(i, 5) g[i] = seg.prod(t[i], l, r); ull mx = QMAX(g, g + 5); int c = 0, id = -1; FOR(i, 5) if (mx == g[i]) { ++c, id = i; } if (c == 1) { s[id] += mx; if (s[id] >= mod) s[id] -= mod; } } else { --x; FOR(i, 5) { if (i == x) { t[i] = seg.apply(t[i], l, r, MA::make_add(1)); } else { t[i] = seg.apply(t[i], l, r, MA::make_mul(0)); } } } } FOR(i, 5) s[i] += seg.prod(t[i], 0, N); print(s); } constexpr int tests = 0, fl = 0, DB = 10; int main() { cin.tie(0)->sync_with_stdio(0); int T = 1; if (fl) cerr.tie(0); if (tests and not fl) IN(T); for (int i = 0; i < T or fl; ++i) { Yorisou(); if (fl and i % DB == 0) cerr << "Case: " << i << '\n'; } return 0; }