#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]; int odd[kN << 2], even[kN << 2]; 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 ; } void addtag(int n, ll x) { if (x == -1) { flag[n] = x; tot[n] = odd[n]; } else { if (flag[n] == -1) push(n); if (x & 1) swap(odd[n], even[n]); flag[n] += x; tot[n] += (odd[n] + even[n]) * x; } return ; } void push(int n) { if (odd[n] + even[n] > 1 && flag[n]) { addtag(n * 2 + 1, flag[n]); addtag(n * 2 + 2, flag[n]); flag[n] = 0; } return ; } void init(int n, int l, int r, int a[]) { flag[n] = 0; if (l == r) { tot[n] = a[l]; if (a[l] & 1) odd[n] = 1, even[n] = 0; else odd[n] = 0, even[n] = 1; } else { int mid = (l + r) >> 1; init(n * 2 + 1, l, mid, a); init(n * 2 + 2, mid + 1, r, a); pull(n); } return ; } void fix(int n, int l, int r, int L, int R, int x) { if (L <= l && r <= R) addtag(n, x); else if (!(L > r || l > R)) { int mid = (l + r) >> 1; push(n); fix(n * 2 + 1, l, mid, L, R, x); fix(n * 2 + 2, mid + 1, r, L, R, x); pull(n); } return ; } 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)); } }