#include #include #include #include #define llint long long #define inf 1e18 using namespace std; typedef pair P; typedef pair T; void calc(llint &s, llint &s2, llint &t, llint &t2) { if(s == 0){ t2 += s2; return; } llint x = 1; if(t == -1) x = -1; if(t2 % 2) x *= -1; x *= s; t = x, t2 = s2; } struct SegTree{ int size; vector seg, seg2, delay, delay2; SegTree(){} SegTree(int size){ this->size = size; seg.resize(1<<(size+1)); seg2.resize(1<<(size+1)); delay.resize(1<<(size+1)); delay2.resize(1<<(size+1)); } void init() { for(int i = 0; i < (1<<(size+1)); i++){ seg[i] = 0, seg2[i] = 0; delay[i] = 0, delay2[i] = 0; } } void eval(int l, int r, int k) { if(delay[k]){ if(delay[k] == -1) seg2[k] = (r-l+1) - seg2[k]; seg[k] = seg2[k]; } if(delay2[k]){ seg[k] += delay2[k] * (r-l+1); if(delay2[k] % 2) seg2[k] = (r-l+1) - seg2[k]; } if(delay[k] || delay2[k]){ if(l < r){ calc(delay[k], delay2[k], delay[k*2], delay2[k*2]); calc(delay[k], delay2[k], delay[k*2+1], delay2[k*2+1]); } delay[k] = delay2[k] = 0; } } void add(int a, int b, int k, int l, int r, llint val, llint val2) { eval(l, r, k); if(b < l || r < a) return; if(a <= l && r <= b){ calc(val, val2, delay[k], delay2[k]); //delay[k] = val, delay2[k] = val2; eval(l, r, k); return; } add(a, b, k*2, l, (l+r)/2, val, val2); add(a, b, k*2+1, (l+r)/2+1, r, val, val2); seg[k] = seg[k*2] + seg[k*2+1]; seg2[k] = seg2[k*2] + seg2[k*2+1]; } void add(int a, int b, llint val, llint val2){ if(a > b) return; add(a, b, 1, 0, (1<> n >> Q; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) seg.add(i, i, 0, a[i]); llint t, l, r, x; for(int q = 1; q <= Q; q++){ cin >> t >> l >> r; if(t == 1){ seg.add(l, r, 1, 0); } if(t == 2){ cin >> x; seg.add(l, r, 0, x); } if(t == 3){ cout << seg.query(l, r) << "\n"; } //for(int i = 1; i <= n; i++) cout << seg.query(i, i) << " "; cout << endl; } flush(cout); return 0; }