#include #include #include #include #include #define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; /*-------------------------------------------------*/ template struct LazySegTree { using MM = function; using MOI = function; using OO = function; LazySegTree(int sz, const MM mm, const MOI moi, const OO oo, const Monoid &M_UNITY, const OperatorMonoid &O_UNITY) : mm(mm), moi(moi), oo(oo), M_UNITY(M_UNITY), O_UNITY(O_UNITY) { init(sz); dat.assign(n << 1, M_UNITY); } LazySegTree(const vector &a, const MM mm, const MOI moi, const OO oo, const Monoid &M_UNITY, const OperatorMonoid &O_UNITY) : mm(mm), moi(moi), oo(oo), M_UNITY(M_UNITY), O_UNITY(O_UNITY) { int a_sz = a.size(); init(a_sz); dat.resize(n << 1); REP(i, a_sz) dat[i + n] = a[i]; for (int i = n - 1; i > 0; --i) dat[i] = mm(dat[i << 1], dat[(i << 1) + 1]); } void update(int a, int b, const OperatorMonoid &value) { update(a, b, value, 1, 0, n); } Monoid query(int a, int b) { return query(a, b, 1, 0, n); } Monoid operator[](const int idx) { return query(idx, idx + 1); } private: int n = 1; const MM mm; const MOI moi; const OO oo; const Monoid M_UNITY; const OperatorMonoid O_UNITY; vector dat; vector lazy; vector need_to_be_eval; void init(int sz) { while (n < sz) n <<= 1; lazy.assign(n << 1, O_UNITY); need_to_be_eval.assign(n << 1, false); } inline void evaluate(int node, int len) { if (need_to_be_eval[node]) { dat[node] = moi(dat[node], lazy[node], len); if (node < n) { lazy[node << 1] = oo(lazy[node << 1], lazy[node]); need_to_be_eval[node << 1] = true; lazy[(node << 1) + 1] = oo(lazy[(node << 1) + 1], lazy[node]); need_to_be_eval[(node << 1) + 1] = true; } lazy[node] = O_UNITY; need_to_be_eval[node] = false; } } void update(int a, int b, const OperatorMonoid &value, int node, int left, int right) { evaluate(node, right - left); if (right <= a || b <= left) return; if (a <= left && right <= b) { lazy[node] = oo(lazy[node], value); need_to_be_eval[node] = true; evaluate(node, right - left); } else { update(a, b, value, node << 1, left, (left + right) >> 1); update(a, b, value, (node << 1) + 1, (left + right) >> 1, right); dat[node] = mm(dat[node << 1], dat[(node << 1) + 1]); } } Monoid query(int a, int b, int node, int left, int right) { evaluate(node, right - left); if (right <= a || b <= left) return M_UNITY; if (a <= left && right <= b) return dat[node]; return mm(query(a, b, node << 1, left, (left + right) >> 1), query(a, b, (node << 1) + 1, (left + right) >> 1, right)); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); struct Node { int even, odd; long long sum; Node() {} Node(int even, int odd, long long sum) : even(even), odd(odd), sum(sum) {} }; struct Ope { long long pre, add; bool mod2; Ope() {} Ope(long long pre, bool mod2, long long add) : pre(pre), mod2(mod2), add(add) {} }; auto mm = [](Node a, Node b) { return Node(a.even + b.even, a.odd + b.odd, a.sum + b.sum); }; auto moi = [](Node a, Ope b, int len) { if (b.pre % 2 == 1) swap(a.even, a.odd); a.sum += b.pre * len; if (b.mod2) a.sum = a.odd; if (b.add % 2 == 1) swap(a.even, a.odd); a.sum += b.add * len; return a; }; auto oo = [](Ope l, Ope v) { Ope res = l; if (v.mod2) { res.pre += res.add + v.pre; res.mod2 = true; res.add = v.add; } else { res.add += v.add; } return res; }; int n, q; cin >> n >> q; vector a; REP(i, n) { int ai; cin >> ai; a.emplace_back(ai % 2 == 0, ai % 2 == 1, ai); } LazySegTree seg(a, mm, moi, oo, Node(0, 0, 0), Ope(0, false, 0)); while (q--) { int query, l, r; cin >> query >> l >> r; --l; --r; if (query == 1) { seg.update(l, r + 1, Ope(0, true, 0)); } else if (query == 2) { int x; cin >> x; seg.update(l, r + 1, Ope(0, false, x)); } else { cout << seg.query(l, r + 1).sum << '\n'; } } return 0; }