#include using namespace std; using ll = long long; using VI = vector; using VL = vector; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define tp(a,i) get(a) inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } templateinline istream& operator>>(istream& is, vector& v) { for (auto& a : v)is >> a; return is; } templateinline void print(const T& a) { cout << a << "\n"; } templateinline void print(const vector& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } templateinline T sum(const vector& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); } template class SegmentTree { using T = typename Op::T; int len, n; vector dat; vector> range; public: SegmentTree(const vector& v) : n(v.size()) { for (len = 1; len < n; len <<= 1); dat.resize(len << 1, Op::unit); range.resize(len << 1); for (int i = 0; i < n; ++i)dat[i + len] = v[i]; for (int i = 0; i < len; ++i) range[i + len] = make_pair(i, i + 1); for (int i = len - 1; 0 < i; --i) { dat[i] = Op::merge(dat[i << 1], dat[i << 1 | 1]); range[i] = make_pair(range[i << 1].first, range[i << 1 | 1].second); } } inline void update(int idx, const T a) { idx += len; dat[idx] = Op::update(dat[idx], a); for (idx >>= 1; 0 < idx; idx >>= 1) dat[idx] = Op::merge(dat[idx << 1], dat[idx << 1 | 1]); } inline int binary_search(const T a) { if (!Op::check(dat[1], a))return n; T cur = Op::unit; int idx = 2; for (; idx < len << 1; idx <<= 1) { if (!Op::check(Op::merge(cur, dat[idx]), a)) cur = Op::merge(cur, dat[idx++]); } return min((idx >> 1) - len, n); } }; template struct node { using T = Type; inline static T unit = 0; inline static T merge(T vl, T vr) { return vl + vr; } inline static T update(T vl, T vr) { return vl + vr; } inline static T check(T vl, T vr) { return vl >= vr; } }; int main() { init(); int n, q; cin >> n >> q; VL a(n); cin >> a; SegmentTree> seg(VI(n, 1)); set s; FOR(i, 0, n) { if (0 < i)a[i] += a[i - 1]; s.emplace(i); } while (q--) { int t, l, r; cin >> t >> l >> r; if (t == 1) { int d = r - l; l = seg.binary_search(l); r = seg.binary_search(r); auto it = s.find(l); FOR(i, 0, d)seg.update(*++it, -1); FOR(i, 0, d)s.erase(s.upper_bound(l)); } else cout << sum(a, seg.binary_search(l), seg.binary_search(r + 1) - 1) << "\n"; } return 0; }