#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<0?-(x):x) #define pow2(x) ((x)*(x)) #define rep(i,n) for(int i=0; i=0; --i) #define repl(i,s,n) for(int i=s; i<=n; ++i) #define replr(i,s,n) for(int i=n; i>=s; --i) #define repf(i,s,n,j) for(int i=s; i<=n; i+=j) #define repe(e,obj) for(auto e : obj) #define SP << " " << #define COL << " : " << #define COM << ", " << #define ARR << " -> " << #define PNT(STR) cout << STR << endl #define POS(X,Y) "(" << X << ", " << Y << ")" #define DEB(A) " (" << #A << ") " << A #define DEBREP(i,n,val) for(int i=0; i P; typedef pair PI; typedef pair IP; typedef pair PP; typedef priority_queue, greater

> pvqueue; #define N (1 << 17) class SegmentTree { ll data[2*N], lazy[2*N], cnt0[2*N], cnt1[2*N]; bool flag[2*N]; int p[2*N]; int n0, n; void propagate(int k) { if(k >= n0-1) return; if(p[k]) { swap(cnt0[2*k+1], cnt1[2*k+1]); p[2*k+1] ^= 1; swap(cnt0[2*k+2], cnt1[2*k+2]); p[2*k+2] ^= 1; p[k] = 0; } if(flag[k]) { data[2*k+1] = cnt1[2*k+1]; data[2*k+2] = cnt1[2*k+2]; if(lazy[2*k+1] & 1) p[2*k+1] ^= 1; if(lazy[2*k+2] & 1) p[2*k+2] ^= 1; lazy[2*k+1] = lazy[2*k+2] = 0; flag[2*k+1] = flag[2*k+2] = true; flag[k] = false; } if(lazy[k] != 0) { if(lazy[k] & 1) { swap(cnt0[2*k+1], cnt1[2*k+1]); swap(cnt0[2*k+2], cnt1[2*k+2]); } data[2*k+1] += lazy[k] * (cnt0[2*k+1] + cnt1[2*k+1]); data[2*k+2] += lazy[k] * (cnt0[2*k+2] + cnt1[2*k+2]); lazy[2*k+1] += lazy[k]; lazy[2*k+2] += lazy[k]; lazy[k] = 0; } } void build(int k) { cnt0[k] = cnt0[2*k+1] + cnt0[2*k+2]; cnt1[k] = cnt1[2*k+1] + cnt1[2*k+2]; data[k] = data[2*k+1] + data[2*k+2]; } void _set(int a, int b, int k, int l, int r) { propagate(k); if(b <= l || r <= a) { return; } if(a <= l && r <= b) { flag[k] = true; data[k] = cnt1[k]; lazy[k] = 0; return; } _set(a, b, 2*k+1, l, (l+r)/2); _set(a, b, 2*k+2, (l+r)/2, r); build(k); } void _add(ll x, int a, int b, int k, int l, int r) { propagate(k); if(b <= l || r <= a) { return; } if(a <= l && r <= b) { if(x & 1) { swap(cnt0[k], cnt1[k]); } data[k] += x * (cnt0[k] + cnt1[k]); lazy[k] += x; return; } _add(x, a, b, 2*k+1, l, (l+r)/2); _add(x, a, b, 2*k+2, (l+r)/2, r); build(k); } ll _query(int a, int b, int k, int l, int r) { propagate(k); if(b <= l || r <= a) { return 0; } if(a <= l && r <= b) { return data[k]; } ll lv = _query(a, b, 2*k+1, l, (l+r)/2); ll rv = _query(a, b, 2*k+2, (l+r)/2, r); build(k); return lv + rv; } public: SegmentTree(int n, ll *a) { n0 = 1; while(n0 < n) n0 <<= 1; for(int i=0; i=0; --i) build(i); } void set(int l, int r) { _set(l, r, 0, 0, n0); } void add(int l, int r, ll x) { _add(x, l, r, 0, 0, n0); } ll query(int l, int r) { return _query(l, r, 0, 0, n0); } }; ll a[N]; int main() { int n, q; cin >> n >> q; rep(i, n) cin >> a[i]; SegmentTree st(n, a); while(q--) { int t, l, r; ll x; cin >> t >> l >> r; switch(t) { case 1: st.set(l-1, r); break; case 2: cin >> x; st.add(l-1, r, x); break; case 3: cout << st.query(l-1, r) << endl; break; } } return 0; }