#include using namespace std; template struct Segt { int psum[n << 2][2]; int64_t vsum[n << 2]; int64_t atag[n << 2]; int ptag[n << 2]; int stag[n << 2]; Segt(vector a) { a.resize(n); function build = [&](int lb, int rb, int t) { atag[t] = 0; ptag[t] = 0; stag[t] = 0; if (rb - lb == 1) { psum[t][a[lb] & 1] = 1; psum[t][~a[lb] & 1] = 0; vsum[t] = a[lb]; return; } int mb = lb + rb >> 1; build(lb, mb, t << 1); build(mb, rb, t << 1 | 1); pull(t); }; build(0, n, 1); } void pull(int t) { for (int i = 0; i < 2; ++i) { psum[t][i] = psum[t << 1][i] + psum[t << 1 | 1][i]; } vsum[t] = vsum[t << 1] + vsum[t << 1 | 1]; } void push(int lb, int rb, int t) { int mb = lb + rb >> 1; if (stag[t]) { for (int c = 0; c < 2; ++c) { swap(psum[t << 1 | c][0], psum[t << 1 | c][1]); stag[t << 1 | c] ^= 1; } stag[t] = 0; } if (ptag[t]) { for (int c = 0; c < 2; ++c) { vsum[t << 1 | c] = psum[t << 1 | c][1]; atag[t << 1 | c] = 0; ptag[t << 1 | c] = 1; } ptag[t] = 0; } if (atag[t]) { vector len({ mb - lb, rb - mb }); for (int c = 0; c < 2; ++c) { vsum[t << 1 | c] += 1LL * len[c] * atag[t]; atag[t << 1 | c] += atag[t]; } atag[t] = 0; } } void mod2(int ql, int qr, int lb = 0, int rb = n, int t = 1) { if (qr <= lb || rb <= ql) return; if (ql <= lb && rb <= qr) { vsum[t] = psum[t][1]; atag[t] = 0; ptag[t] = 1; return; } push(lb, rb, t); int mb = lb + rb >> 1; mod2(ql, qr, lb, mb, t << 1); mod2(ql, qr, mb, rb, t << 1 | 1); pull(t); } void add(int v, int ql, int qr, int lb = 0, int rb = n, int t = 1) { if (qr <= lb || rb <= ql) return; if (ql <= lb && rb <= qr) { vsum[t] += 1LL * (rb - lb) * v; atag[t] += v; if (v & 1) { stag[t] ^= 1; swap(psum[t][0], psum[t][1]); } return; } push(lb, rb, t); int mb = lb + rb >> 1; add(v, ql, qr, lb, mb, t << 1); add(v, ql, qr, mb, rb, t << 1 | 1); pull(t); } int64_t query(int ql, int qr, int lb = 0, int rb = n, int t = 1) { if (qr <= lb || rb <= ql) return 0; if (ql <= lb && rb <= qr) return vsum[t]; push(lb, rb, t); int mb = lb + rb >> 1; return query(ql, qr, lb, mb, t << 1) + query(ql, qr, mb, rb, t << 1 | 1); } }; int main() { ios::sync_with_stdio(false); int N, Q; cin >> N >> Q; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } static Segt<(1 << 17)> tree(A); while (Q--) { int P; cin >> P; if (P == 1) { int L, R; cin >> L >> R; tree.mod2(L - 1, R); } else if (P == 2) { int L, R, X; cin >> L >> R >> X; tree.add(X, L - 1, R); } else { int L, R; cin >> L >> R; cout << tree.query(L - 1, R) << endl; } } return 0; }