#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 998244353; const ll INF = mod * mod; typedef pair P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i=0;i--) #define Rep(i,sta,n) for(int i=sta;i=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef pair LP; typedef vector vec; typedef long double ld; typedef pair LDP; const ld eps = 1e-5; const ld pi = acos(-1.0); struct SegT { private: int n; vector node; vector odds; vector> lazy; vector num; const ll init_c = 0; public: SegT(vector a) { int sz = a.size(); n = 1; while (n < sz)n <<= 1; node.resize(2 * n - 1, 0); lazy.resize(2 * n - 1); num.resize(2 * n - 1, 0); odds.resize(2 * n - 1, 0); rep(i, sz) { if (a[i] % 2) { odds[i + n - 1] = 1; } num[i + n - 1] = 1; } per(i, n - 1) { odds[i] = odds[2 * i + 1] + odds[2 * i + 2]; num[i] = num[2 * i + 1] + num[2 * i + 2]; } rep(i, sz) { node[i+n-1] = a[i]; } per(i, n - 1) { node[i] = f(node[2 * i + 1], node[2 * i + 2]); } } ll f(ll a, ll b) { return a+b; } void add1(int k, ll x) { if (lazy[k].empty() || lazy[k].back() < 0) { lazy[k].push_back(x); } else { lazy[k].back() += x; } } void add2(int k) { if (lazy[k].size() && lazy[k].back() < 0)return; if (lazy[k].size() >= 2) { ll sum = 0; rep(i, lazy[k].size()) { if (lazy[k][i] >= 0)sum += lazy[k][i]; } lazy[k] = { sum % 2,-1 }; } else { lazy[k].push_back(-1); } } void add3(int k, ll x) { if (x < 0)add2(k); else add1(k, x); } void eval(int k, int l, int r) { rep(i, lazy[k].size()) { ll x = lazy[k][i]; if (x >= 0) { node[k] += x*num[k]; if (x % 2) { odds[k] = num[k] - odds[k]; } //cout << "! " << k << " " << odds[k] << endl; } else { node[k] = odds[k]; } if (r - l > 1) { add3(2 * k + 1, x); add3(2 * k + 2, x); } } lazy[k].clear(); } void add(ll x, int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0)r = n; eval(k, l, r); if (r <= a || b <= l)return; if (a <= l && r <= b) { add3(k,x); eval(k, l, r); } else { add(x, a, b, k * 2 + 1, l, (l + r) / 2); add(x, a, b, k * 2 + 2, (l + r) / 2, r); node[k] = f(node[k * 2 + 1], node[k * 2 + 2]); odds[k] = odds[k * 2 + 1] + odds[k * 2 + 2]; } } ll query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0)r = n; eval(k, l, r); if (r <= a || b <= l)return init_c; if (a <= l && r <= b)return node[k]; else { ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return vl+vr; } } }; void solve() { int n, q; cin >> n >> q; vector a(n); rep(i, n) { cin >> a[i]; } SegT st(a); rep(i, q) { int t, l, r; cin >> t >> l >> r; l--; r--; if (t == 1) { st.add(-1, l, r + 1); } else if (t == 2) { int x; cin >> x; st.add(x, l, r + 1); } else { ll z = st.query(l, r + 1); cout << z << endl; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(50); //init(); solve(); //cout << "finish" << endl; //stop return 0; }