#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define ll long long template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using S = array; using F = array; S e() { return {0, 0, 0}; } F id() { return {1, 0, 0, 0, 1, 0, 0, 0, 1}; } S op(S x, S y) { S z{}; rep(i, 0, 3) z[i] = x[i] + y[i]; return z; } S mapping(F f, S x) { S y{}; rep(i, 0, 3) rep(j, 0, 3) y[i] += f[3 * i + j] * x[j]; return y; } F composition(F f, F g) { F h{}; rep(i, 0, 3) rep(j, 0, 3) rep(k, 0, 3) h[3 * i + j] += f[3 * i + k] * g[3 * k + j]; return h; } int main() { int n, q; cin >> n >> q; vector a(n); rep(i, 0, n) cin >> a[i]; vector b(n); rep(i, 0, n) b[i] = {a[i], 1 - (a[i] & 1), a[i] & 1}; lazy_segtree seg(b); while (q--) { int type; cin >> type; if (type == 1) { int l, r; cin >> l >> r; seg.apply(l - 1, r, {0, 0, 1, 0, 1, 0, 0, 0, 1}); } if (type == 2) { int l, r, x; cin >> l >> r >> x; int y = x & 1; seg.apply(l - 1, r, {1, x, x, 0, 1 - y, y, 0, y, 1 - y}); } if (type == 3) { int l, r; cin >> l >> r; cout << seg.prod(l - 1, r)[0] << "\n"; } } }