#include #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pi; typedef pair pl; typedef pair ppi; typedef vector vi; typedef vector vl; typedef vector mat; typedef complex comp; void Debug() {cout << '\n'; } templatevoid Debug(FIRST arg, REST... rest){ cout<ostream& operator<<(ostream& out,const vector& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<ostream& operator<<(ostream& out,const pair& v){ out<<"("< vx; struct segtree { // this is piece of shit. use BIT int n; vl sum, lazy, zero; void init(int mx) { n = 1; while(n < mx) n *= 2; sum = vl(n * 2, 0); lazy = vl(n * 2, 0); zero = vl(n * 2, 0); } segtree(int mx = 0) { init(mx); } inline void lazy_eval(int k, int l, int r) { int m = (l + r) / 2; if(lazy[k]) { sum[k * 2 + 1] += (vx[m] - vx[l]) * lazy[k];//if range_min, erase (m - l) lazy[k * 2 + 1] += lazy[k]; sum[k * 2 + 2] += (vx[r] - vx[m]) * lazy[k];//here too lazy[k * 2 + 2] += lazy[k]; lazy[k] = 0; } } void app(int a, int b, ll s, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { sum[k] += (vx[r] - vx[l]) * s; //here too lazy[k] = lazy[k] + s; } else { zero[k] = 1; lazy_eval(k, l, r); app(a, b, s, k * 2 + 1, l, (l + r) / 2); app(a, b, s, k * 2 + 2, (l + r) / 2, r); sum[k] = sum[k * 2 + 1] + sum[k * 2 + 2]; } } void cln(int a, int b, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { if(zero[k]) { cln(a, b, k * 2 + 1, l, (l + r) / 2); cln(a, b, k * 2 + 2, (l + r) / 2, r); } zero[k] = 0; sum[k] = 0; lazy[k] = 0; } else { lazy_eval(k, l, r); cln(a, b, k * 2 + 1, l, (l + r) / 2); cln(a, b, k * 2 + 2, (l + r) / 2, r); sum[k] = sum[k * 2 + 1] + sum[k * 2 + 2]; } } ll ga(int a, int b, int k, int l, int r) { if(b <= l || r <= a) return ll(); if(a <= l && r <= b) return sum[k]; else { lazy_eval(k, l, r); ll lv = ga(a, b, k * 2 + 1, l, (l + r) / 2); ll rv = ga(a, b, k * 2 + 2, (l + r) / 2, r); return lv + rv; } } void show() { vector tmp; rep(i, 0, n) tmp.push_back(get(i, i + 1)); debug(tmp); } ll get(int a, int b) { return ga(a, b, 0, 0, n); } //[a, b) void update(int a, int b, ll s) { app(a, b, s, 0, 0, n); } //[a, b) void clean(int a, int b) { cln(a, b, 0, 0, n); } }; int fd(ll a) { return lower_bound(all(vx), a) - vx.begin(); } int N, Q; ll X[MAX_N], L[MAX_N], R[MAX_N]; ll ans[MAX_N]; segtree seg[5]; void solve() { cin >> N >> Q; rep(i, 0, Q) { cin >> X[i] >> L[i] >> R[i]; R[i]++; vx.pb(L[i]); vx.pb(R[i]); } sort(all(vx)); vx.erase(unique(all(vx)), vx.end()); rep(i, 0, 5) seg[i].init(sz(vx)); // debug(vx); rep(i, 0, Q) { int l = fd(L[i]), r = fd(R[i]); // debug(l, r, L[i], R[i]); if(X[i] == 0) { vector vec(5); rep(j, 0, 5) vec[j] = seg[j].get(l, r); int at = -1; ll mv = -linf; rep(j, 0, 5) { if(mv < vec[j]) { at = j; mv = vec[j]; } else if(mv == vec[j]) at = -1; } if(at != -1) ans[at] += vec[at]; } else { rep(j, 0, 5) { if(j == X[i] - 1) seg[j].update(l, r, 1); else seg[j].clean(l, r); } } } rep(j, 0, 5) { ans[j] += seg[j].get(0, sz(vx)); cout << ans[j] << (j == 4 ? '\n' : ' '); } } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }