#include #include #include #include using namespace __gnu_pbds; using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template void chmax(T& a, const T& b) {a = max(a, b);} template void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; VL a(n), s(n + 1); rep(i, n) cin >> a[i]; rep(i, n) s[i+1] = s[i] + a[i]; VI tmp(n); iota(all(tmp), 0); tree, rb_tree_tag, tree_order_statistics_node_update> t_l(all(tmp)); tree, rb_tree_tag, tree_order_statistics_node_update> t_r(all(tmp)); while(q--) { int type, l, r; cin >> type >> l >> r; l--, r--; if (type == 1) { { auto it1 = t_r.find_by_order(l); auto it2 = t_r.find_by_order(r); while(it1 != it2) it1 = t_r.erase(it1); } { auto it1 = t_l.find_by_order(l); auto it2 = t_l.find_by_order(r); while(it1 != it2) { auto tmp = it2; tmp--; t_l.erase(it2); it2 = tmp; } } } else { int i = *t_l.find_by_order(l); int j = *t_r.find_by_order(r); cout << s[j + 1] - s[i] << '\n'; } } }