#include using namespace std; const long long INF = 1000000000000000; template struct lazy_segment_tree{ int N; vector ST; vector lazy; lazy_segment_tree(vector &A){ int n = A.size(); N = 1; while (N < n){ N *= 2; } ST = vector(N * 2 - 1, 0); lazy = vector(N * 2 - 1, INF); for (int i = 0; i < n; i++){ ST[N - 1 + i] = A[i]; } for (int i = N - 2; i >= 0; i--){ ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2]; } } void eval(int i, int l, int r){ if (lazy[i] != INF){ if (i < N - 1){ lazy[i * 2 + 1] = lazy[i]; lazy[i * 2 + 2] = lazy[i]; } ST[i] = lazy[i] * (r - l); lazy[i] = INF; } } void range_update(int L, int R, T x, int i, int l, int r){ eval(i, l, r); if (R <= l || r <= L){ return; } else if (L <= l && r <= R){ lazy[i] = x; eval(i, l, r); } else { int m = (l + r) / 2; range_update(L, R, x, i * 2 + 1, l, m); range_update(L, R, x, i * 2 + 2, m, r); ST[i] = ST[i * 2 + 1] + ST[i * 2 + 2]; } } void range_update(int L, int R, T x){ range_update(L, R, x, 0, 0, N); } T range_sum(int L, int R, int i, int l, int r){ eval(i, l, r); if (R <= l || r <= L){ return 0; } else if (L <= l && r <= R){ return ST[i]; } else { int m = (l + r) / 2; return range_sum(L, R, i * 2 + 1, l, m) + range_sum(L, R, i * 2 + 2, m, r); } } T range_sum(int L, int R){ return range_sum(L, R, 0, 0, N); } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; i++){ cin >> A[i]; } vector B(N, 1); lazy_segment_tree ST1(A), ST2(B); for (int i = 0; i < Q; i++){ int T, l, r; cin >> T >> l >> r; l--; r--; int tv1 = N, fv1 = -1; while (tv1 - fv1 > 1){ int mid = (tv1 + fv1) / 2; if (ST2.range_sum(0, mid + 1) > l){ tv1 = mid; } else { fv1 = mid; } } l = tv1; int tv2 = N, fv2 = -1; while (tv2 - fv2 > 1){ int mid = (tv2 + fv2) / 2; if (ST2.range_sum(0, mid + 1) > r){ tv2 = mid; } else { fv2 = mid; } } r = tv2; if (T == 1){ long long S = ST1.range_sum(l, r + 1); ST1.range_update(l, l + 1, S); ST1.range_update(l + 1, r + 1, 0); ST2.range_update(l + 1, r + 1, 0); } if (T == 2){ long long S = ST1.range_sum(l, r + 1); cout << S << "\n"; } } }