#include #include #include #include #include #include #include #include #include #include #include //https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_H using namespace std; templatestruct LazySegTree { vector seg; vector lazy; long long N = 1; LazySegTree (long long n) : LazySegTree(vector(n, e())) {} LazySegTree (const vector &v){ long long n = v.size(); while (N < n) N *= 2; seg.resize(N*2-1, e()); lazy.resize(N*2-1, id()); for (long long i=0; i=0; i--){ seg[i] = op(seg[i*2+1], seg[i*2+2]); } } void eval (long long idx, long long bitl, long long bitr){ if (lazy[idx] != id()){ seg[idx] = mapping(lazy[idx], seg[idx]); if (bitl != bitr){ lazy[2*idx+1] = composition(lazy[idx], lazy[2*idx+1]); lazy[2*idx+2] = composition(lazy[idx], lazy[2*idx+2]); } lazy[idx] = id(); } } //a[i] -> f(a[i]) for l<=i<=r void set (long long l, long long r, F val){ _set(l, r, val, 0, 0, N-1); } void _set (long long l, long long r, F val, long long idx, long long bitl, long long bitr){ eval(idx, bitl, bitr); if (r < bitl || l > bitr) return; if (l <= bitl && bitr <= r){ lazy[idx] = composition(lazy[idx], val); eval(idx, bitl, bitr); } else{ long long bitm = (bitl+bitr)/2; _set(l, r, val, idx*2+1, bitl, bitm); _set(l, r, val, idx*2+2, bitm+1, bitr); seg[idx] = op(seg[idx*2+1], seg[idx*2+2]); } } //op(a[l], ..., a[r]) S prod (long long l, long long r) { return _prod(l, r, 0, 0, N-1); } S all_prod() const{ return seg[0]; } S _prod (long long l, long long r, long long idx, long long bitl, long long bitr) { if (r < bitl || l > bitr) return e(); eval(idx, bitl, bitr); if (l <= bitl && bitr <= r) return seg[idx]; long long bitm = (bitl+bitr)/2; return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr)); } S get (long long i) { return prod(i, i); } void show() const{ for (int i=0; i> N >> Q; LazySegTree tree(N); vector> BLR(Q); for (int i=0; i> l >> r >> b; l--; r--; BLR[i] = {b, l, r}; } sort(BLR.begin(), BLR.end()); for (int i=0; i