#include typedef long long int ll; constexpr int kN = int(1E5 + 10); void swap(int &a, int &b) { int temp = a; a = b; b = temp; return ; } struct seg_tree { ll tot[kN << 2], flag[kN << 2]; bool Mod[kN << 2]; int odd[kN << 2], even[kN << 2], sz[kN << 2]; inline void pull(int n) { tot[n] = tot[n * 2 + 1] + tot[n * 2 + 2]; odd[n] = odd[n * 2 + 1] + odd[n * 2 + 2]; even[n] = even[n * 2 + 1] + even[n * 2 + 2]; return ; } inline void addtag(int n, ll x) { if (x & 1) swap(odd[n], even[n]); flag[n] += x; tot[n] += sz[n] * x; return ; } inline void change(int n) { tot[n] = odd[n]; if (flag[n]) { addtag(n * 2 + 1, flag[n]); addtag(n * 2 + 2, flag[n]); flag[n] = 0; } Mod[n] = true; return ; } inline void push(int n) { if (Mod[n]) { change(n * 2 + 1); change(n * 2 + 2); Mod[n] = false; } if (flag[n]) { addtag(n * 2 + 1, flag[n]); addtag(n * 2 + 2, flag[n]); flag[n] = 0; } return ; } inline void init(int n, int l, int r, int a[]) { flag[n] = 0; Mod[n] = false; if (l == r) { tot[n] = a[l]; if (a[l] & 1) odd[n] = 1, even[n] = 0; else odd[n] = 0, even[n] = 1; sz[n] = 1; } else { int mid = (l + r) >> 1; init(n * 2 + 1, l, mid, a); init(n * 2 + 2, mid + 1, r, a); sz[n] = sz[n * 2 + 1] + sz[n * 2 + 2]; pull(n); } return ; } inline void fix(int n, int l, int r, int L, int R, int x) { if (L <= l && r <= R) { if (x == -1) change(n); else addtag(n, x); } else if (!(L > r || l > R)) { int mid = (l + r) >> 1; push(n); if (L <= mid) fix(n * 2 + 1, l, mid, L, R, x); if (R > mid) fix(n * 2 + 2, mid + 1, r, L, R, x); pull(n); } return ; } inline ll ask(int n, int l, int r, int L, int R) { if (L <= l && r <= R) return tot[n]; else if (l > R || L > r) return 0; else { int mid = (l + r) >> 1; push(n); return ask(n * 2 + 1, l, mid, L, R) + ask(n * 2 + 2, mid + 1, r, L, R); } } }; seg_tree sg; int a[kN]; int main() { int n, q, k, l, r, x; scanf("%d%d", &n, &q); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sg.init(0, 1, n, a); while (q--) { scanf("%d%d%d", &k, &l, &r); if (k == 1) sg.fix(0, 1, n, l, r, -1); else if (k == 2) { scanf("%d", &x); sg.fix(0, 1, n, l, r, x); } else printf("%lld\n", sg.ask(0, 1, n, l, r)); } }