#include int ri() { int n; scanf("%d", &n); return n; } struct SegTree { std::vector data; // sum std::vector odds; // num of odds std::vector lazy; // lazy std::vector lazyf;// lazy of flush std::vector num; int n; SegTree (const std::vector &a) { for (n = 1; n < (int) a.size(); n *= 2); data.resize(2 * n); odds.resize(2 * n); lazy.resize(2 * n); lazyf.resize(2 * n); num.resize(2 * n); for (int i = 0; i < (int) a.size(); i++) data[i + n] = a[i], odds[i + n] = a[i] & 1; for (int i = n; i < 2 * n; i++) num[i] = 1; for (int i = n - 1; i; i--) update(i), num[i] = num[i << 1] * 2; } void flush_(int i) { if (lazy[i]) { if (lazy[i] & 1) odds[i] = num[i] - odds[i]; if (i < n) { flushf(i << 1); flushf(i << 1 | 1); lazy[i << 1] += lazy[i]; lazy[i << 1 | 1] += lazy[i]; update(i); } data[i] += (int64_t) num[i] * lazy[i]; lazy[i] = 0; } } void flushf(int i) { if (lazyf[i]) { lazy[i] = 0; data[i] = odds[i]; if (i < n) { lazyf[i << 1] = true; lazyf[i << 1 | 1] = true; } lazyf[i] = false; } } void flush(int i) { flushf(i); flush_(i); } void update(int i) { if (i < n) { data[i] = data[i << 1] + data[i << 1 | 1]; odds[i] = odds[i << 1] + odds[i << 1 | 1]; } } void add(int l, int r, int x, int i = 1, int node_l = 0, int node_r = 0) { if (!node_r) node_r = n; if (l == r) return; flush(i); if (l == node_l && r == node_r) { lazy[i] += x; flush(i); return; } if (r <= node_l || l >= node_r) return; int mid = node_l + (node_r - node_l) / 2; add(std::max(node_l, l), std::min(mid, r), x, i << 1, node_l, mid); add(std::max(mid, l), std::min(node_r, r), x, i << 1 | 1, mid, node_r); update(i); } void mod2(int l, int r, int i = 1, int node_l = 0, int node_r = 0) { if (!node_r) node_r = n; if (l == r) return; flush(i); if (l == node_l && r == node_r) { lazyf[i] = true; flush(i); return; } if (r <= node_l || l >= node_r) return; int mid = node_l + (node_r - node_l) / 2; mod2(std::max(node_l, l), std::min(mid, r), i << 1, node_l, mid); mod2(std::max(mid, l), std::min(node_r, r), i << 1 | 1, mid, node_r); update(i); } int64_t sum(int l, int r, int i = 1, int node_l = 0, int node_r = 0) { if (!node_r) node_r = n; if (l == r) return 0; flush(i); if (l == node_l && r == node_r) return data[i]; if (r <= node_l || l >= node_r) return 0; int mid = node_l + (node_r - node_l) / 2; return sum(std::max(node_l, l), std::min(mid, r), i << 1, node_l, mid) + sum(std::max(mid, l), std::min(node_r, r), i << 1 | 1, mid, node_r); } }; int main() { int n = ri(); int q = ri(); std::vector a(n); for (int i = 0; i < n; i++) a[i] = ri(); SegTree tree(a); for (int i = 0; i < q; i++) { int t = ri(); int l = ri() - 1, r = ri() - 1; if (t == 1) { tree.mod2(l, r + 1); } else if (t == 2) { tree.add(l, r + 1, ri()); } else printf("%lld\n", (long long) tree.sum(l, r + 1)); } return 0; }