#include using namespace std; using ll = long long; templatestruct SegTree { private: vector seg; int N = 1; S _prod (int l, int r, int idx, int bitl, int bitr) const{ if (r < bitl || l > bitr) return e(); if (l <= bitl && bitr <= r) return seg[idx]; ll bitm = (bitl+bitr)/2; return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr)); } public: SegTree (ll n) : SegTree(vector(n, e())) {} SegTree (const vector &v){ ll n = v.size(); while (N < n) N *= 2; seg.resize(N*2-1, e()); for (ll i=0; i=0; i--) seg[i] = op(seg[i*2+1], seg[i*2+2]); } void set(int loc, S val){ loc += N-1; seg[loc] = val; while (loc != 0) loc = (loc-1)/2, seg[loc] = op(seg[loc*2+1], seg[loc*2+2]); } S prod (int l, int r) const {return _prod(l, r, 0, 0, N-1);} S all_prod() const {return seg[0];} S get (int i) const{return seg[i+N-1];} void show() const{ for (int i=N-1; i> N; vector v(N); for (int i=0; i> v[i]; SegTree tree(v); for (int l=0; l