//#define _GLIBCXX_DEBUG #include using namespace std; #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} #undef _GLIBCXX_DEBUG string to_string(const string &s) {return '"' + s + '"';} string to_string(const char *s) {return to_string(string(s));} string to_string(bool b) {return b?"true":"false";} string to_string(vector v) { string res = "{"; for(int i = 0; i < int(v.size()); i++) { if(i) res += ", "; res += to_string(v[i]); } res += "}"; return res; } template string to_string(bitset v) { string res; for(size_t i = 0; i < N; i++) res += char('0' + v[i]); return res; } template string to_string(pair); template string to_string(tuple); template string to_string(tuple); template string to_string(A v) { bool first = true; string res = "{"; for(const auto &x:v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template string to_string(pair p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template string to_string(tuple t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")"; } template string to_string(tuple t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")"; } void debug_out() {cerr << endl;} template void debug_out(Head H, Tail... T) { cerr << ' ' << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 822 #endif template struct SegTreeL { using FX = function; using FA = function; using FF = function; int n, _n, log; FX fx; FA fa; FF ff; const S es; const F ef; vector dat; vector laz; // es_はSの零元 ef_はFとして使わない値かつff_(val, ef_)がうまくいく数 SegTreeL(int n_, FX fx_, FA fa_, FF ff_, S es_, F ef_) : fx(fx_), fa(fa_), ff(ff_), es(es_), ef(ef_), n(1), _n(n_), log(0) { while(n_ > n) n <<= 1, log++; dat.assign(n*2-1, es); laz.assign(n*2-1, ef); build(); } SegTreeL(vector &v, FX fx_, FA fa_, FF ff_, S es_, F ef_) : fx(fx_), fa(fa_), ff(ff_), es(es_), ef(ef_), n(1), _n(int(v.size())), log(0) { while(_n > n) n <<= 1, log++; dat.assign(n*2-1, es); laz.assign(n*2-1, ef); copy(v.begin(), v.end(), dat.begin()+n-1); build(); } inline int chld(int k) {return k*2+1;} inline int chrd(int k) {return k*2+2;} void set(int i, S s) {dat[i+n-1] = s;} void build() { for(int k = n-2; k >= 0; k--) dat[k] = fx(dat[chld(k)], dat[chrd(k)]); } void eval(int k) { if(laz[k] == ef) return; if(k < n-1) { laz[chld(k)] = ff(laz[chld(k)], laz[k]); laz[chrd(k)] = ff(laz[chrd(k)], laz[k]); } dat[k] = fa(dat[k], laz[k]); laz[k] = ef; } void eval_thrice(int k) { eval(k); if(k >= n-1) return; eval(chld(k)); eval(chrd(k)); } void update(int a, int b, F x, int k, int l, int r) { eval(k); if(a <= l and r <= b) { laz[k] = ff(laz[k], x); eval(k); } else if(a < r and l < b) { update(a, b, x, chld(k), l, (l+r)>>1); update(a, b, x, chrd(k), (l+r)>>1, r); dat[k] = fx(dat[chld(k)], dat[chrd(k)]); } } void update(int a, int b, F x) {update(a, b, x, 0, 0, n);} void update2(int id, S x) { eval2(id, 0, 0, n); int now = id+n-1; dat[now] = x; while(now) { eval(now&1?now+1:now-1); now = (now-1)/2; dat[now] = fx(dat[chld(now)], dat[chrd(now)]); } } void eval2(int id, int k, int l, int r) { if(l == r-1) return; eval(k); if((l+r)/2 > id) eval2(id, chld(k), l, (l+r)/2); else eval2(id, chrd(k), (l+r)/2, r); if(l == r-2) { eval(chld(k)); eval(chrd(k)); } } S query(int a, int b, int k, int l, int r) { eval(k); if(r <= a or b <= l) return es; else if(a <= l and r <= b) return dat[k]; else { S vl = query(a, b, chld(k), l, (l+r)>>1); S vr = query(a, b, chrd(k), (l+r)>>1, r); return fx(vl, vr); } } S query(int a, int b) {return query(a, b, 0, 0, n);} template int max_right(int l, G g) { assert(g(es)); if(l == _n) return _n; l += n; for(int i = log; i >= 0; i--) eval_thrice((l>>i)-1); S now = es; do{ while(~l&1) l >>= 1; if(!g(fx(now, dat[l-1]))) { while(l < n) { eval_thrice(l-1); l <<= 1; if(g(fx(now, dat[l-1]))) { now = fx(now, dat[l++ - 1]); } } return l-n; } now = fx(now, dat[l++ - 1]); } while((l & -l) != l); return _n; } template int min_left(int r, G g) { assert(g(es)); if(r == 0) return 0; r += n; for(int i = log; i >= 0; i--) eval_thrice(((r-1)>>i)-1); S now = es; do{ r--; while(r > 1 and (r&1)) r >>= 1; if(!g(fx(dat[r-1], now))) { while(r < n) { eval_thrice(r-1); r = chld(r); if(g(fx(dat[r-1], now))) { now = fx(dat[--r], now); } } return r+1-n; } now = fx(dat[r-1], now); } while((r & -r) != r); return 0; } //debug inline const S operator[](const int i) {return query(i, i+1);} void print() {for(int i = 0; i < n; i++) cerr << (*this)[i] << (i == n-1?'\n':' ');} }; //head int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector pref(n+1); rep(i, n) { int a; cin >> a; pref[i+1] = pref[i]+a; } vector

Z(n, {1, 1}); SegTreeL seg(Z, [](P i, P j)->P{return {i.first+j.first, i.second+j.second};}, [](P i, int j)->P{return {i.second*j, i.second};}, [](int i, int j){return j;}, P(0, 0), -1); auto get = [&](int i) { if(i < 0) return i; return seg.max_right(0, [i](P x){return x.first <= i;}); }; while(q--) { int t, l, r; cin >> t >> l >> r; //debug(t, l, r); l--; if(t == 1) { l = get(l); r = get(r); seg.update(l, r-1, 0); //rep(i, n) debug(i, get(i)); } else { cout << pref[get(r-1)+1]-pref[get(l-1)+1] << '\n'; } } }