#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, q; cin >> n >> q; V a(n); for (auto&& e : a) cin >> e; constexpr int B = 512; V sum((n + B - 1) / B); V oc((n + B - 1) / B); V ec((n + B - 1) / B); V<> b((n + B - 1) / B); V laz((n + B - 1) / B); auto push = [&](int k) -> void { for (int i = k * B; i < min((k + 1) * B, n); ++i) { if (b[k] == 1) a[i] &= 1; if (b[k] == 2) a[i] = ~a[i] & 1; a[i] += laz[k]; } b[k] = laz[k] = 0; }; auto build = [&](int k) -> void { for (int i = k * B; i < min((k + 1) * B, n); ++i) { sum[k] += a[i]; oc[k] += a[i] & 1; ec[k] += ~a[i] & 1; } }; auto act = [&](int l, int r, lint x) -> void { if (l % B) { push(l / B); while (l < r and l % B) { if (x == -1) a[l] &= 1; else a[l] += x; ++l; } build((l - 1) / B); } if (r % B) { push(r / B); while (l < r and r % B) { --r; if (x == -1) a[r] &= 1; else a[r] += x; } build(r / B); } while (l < r) { if (x == -1) { sum[l / B] = oc[l / B]; b[l / B] = 1; laz[l / B] = 0; } else { sum[l / B] += (oc[l / B] + ec[l / B]) * x; if (x & 1) swap(oc[l / B], ec[l / B]); } l += B; } }; auto acc = [&](int l, int r) -> lint { lint res = 0; if (l % B) { push(l / B); while (l < r and l % B) { res += a[l]; ++l; } build((l - 1) / B); } if (r % B) { push(r / B); while (l < r and r % B) { --r; res += a[r]; } build(r / B); } while (l < r) { res += sum[l / B]; l += B; } return res; }; for (int k = 0; k < (n + B - 1) / B; ++k) { build(k); } while (q--) { int tp; cin >> tp; int l, r; cin >> l >> r, --l; if (tp == 1) { act(l, r, -1); } else if (tp == 2) { int x; cin >> x; act(l, r, x); } else { cout << acc(l, r) << '\n'; } } }