#include using namespace std; // 0-indexed template struct SegmentTreeLaze { // a,b:T c,d:E e:E(unit) // g(f(a,b),c) = f(g(a,c),g(b,c)) // g(g(a,c),d) = g(a,h(c,d)) // g(a,e) = a typedef function F; typedef function G; typedef function H; int n, height; F f; G g; H h; T tunit; E eunit; vector dat; vector laz; SegmentTreeLaze(){}; SegmentTreeLaze(int newn, F f, G g, H h, T nt, E ne) : f(f), g(g), h(h), tunit(nt), eunit(ne) { init(newn); } SegmentTreeLaze(const vector &v, F f, G g, H h, T nt, E ne) : f(f), g(g), h(h), tunit(nt), eunit(ne) { int _n = v.size(); init(v.size()); for (int i = 0; i < _n; ++i) dat[n + i] = v[i]; for (int i = n - 1; i; --i) dat[i] = f(dat[i << 1], dat[(i << 1) | 1]); } void init(int newn) { n = 1, height = 0; while (n < newn) n <<= 1, ++height; dat.assign(n << 1, tunit); laz.assign(n << 1, eunit); } inline T reflect(int k) { return laz[k] == eunit ? dat[k] : g(dat[k], laz[k]); } inline void eval(int k) { if (laz[k] == eunit) return; laz[k << 1] = h(laz[k << 1], laz[k]); laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]); dat[k] = reflect(k); laz[k] = eunit; } inline void thrust(int k) { for (int i = height; i; --i) eval(k >> i); // reset query dat[k] = reflect(k); laz[k] = eunit; } void recalc(int k) { while (k >>= 1) dat[k] = f(reflect(k << 1), reflect((k << 1) | 1)); } // [a,b) void update(int a, int b, E newdata) { thrust(a += n); thrust(b += n - 1); for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) laz[l] = h(laz[l], newdata), l++; if (r & 1) --r, laz[r] = h(laz[r], newdata); } recalc(a); recalc(b); } void set_val(int k, T newdata) { thrust(k += n); dat[k] = newdata; laz[k] = eunit; recalc(k); } // [a,b) T query(int a, int b) { thrust(a += n); thrust(b += n - 1); T vl = tunit, vr = tunit; for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) vl = f(vl, reflect(l++)); if (r & 1) vr = f(reflect(--r), vr); } return f(vl, vr); } }; struct dat { long long wid, sum, odd; dat(long long _w = 1, long long _s = 0, long long _o = 0) : wid(_w), sum(_s), odd(_o) {} }; struct opt { int mod; long long x; opt(int _m = 0, long long _x = 0) : mod(_m), x(_x) {} bool operator==(const opt &r) const { return mod == r.mod && x == r.x; } }; int n, q; vector v; SegmentTreeLaze seg; int main() { cin >> n >> q; v.resize(n); for (int i = 0; i < n; ++i) { cin >> v[i].sum; v[i].odd = v[i].sum & 1; } { // make seg auto f = [](dat l, dat r) { return dat(l.wid + r.wid, l.sum + r.sum, l.odd + r.odd); }; auto g = [](dat l, opt r) { if (r.mod == 2) l.odd = l.wid - l.odd; if (r.mod) l.sum = l.odd; l.sum += l.wid * r.x; if (r.x & 1) l.odd = l.wid - l.odd; return l; }; auto h = [](opt l, opt r) { if (r.mod) { l.mod = 1 + ((l.mod / 2) ^ (r.mod / 2) ^ (l.x & 1)); l.x = 0; } l.x += r.x; return l; }; seg = SegmentTreeLaze(v, f, g, h, dat(0), opt()); } { // query for (int i = 0; i < q; ++i) { long long a, b, c, x; cin >> a >> b >> c; if (a == 1) seg.update(b - 1, c, opt(1, 0)); else if (a == 2) { cin >> x; seg.update(b - 1, c, opt(0, x)); } else cout << seg.query(b - 1, c).sum << endl; } } return 0; }