#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using namespace std; template ostream& operator<<(ostream& o,const pair &p){ return o<<"("< ostream& operator<<(ostream& o,const vector &vc){ o<<"{"; for(const T& v:vc) o< using V = vector; template using VV = vector>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #ifdef LOCAL #define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl #else #define show(x) true #endif template struct segtree_lazy{ using val_t = typename Handler::val_t; using opr_t = typename Handler::opr_t; int N; vector val; vector lazy; segtree_lazy(){} segtree_lazy(int n){init(n);} segtree_lazy(const vector& vc){init(vc);} void init(int n){ N=1; while(N& vc){ int n = vc.size(); N=1; while(N0;i--) val[i] = val[i*2] + val[i*2+1]; lazy.assign(N*2,opr_t::e()); } val_t query(int a,int b,int l=0,int r=-1,int k=1){ //query_calc if(r==-1) r=N; if(b<=l||r<=a) return val_t::e(); if(a<=l&&r<=b) return val[k]; propagate(l,r,k); return query(a,b,l,(l+r)/2,k*2) + query(a,b,(l+r)/2,r,k*2+1); } void addlazy(int k,const opr_t &f){ Handler::setg2fg(f,lazy[k]); val[k] = Handler::act(f,val[k]); } void update(int a,int b,const opr_t &f,int l=0,int r=-1,int k=1){ //query_update if(r==-1) r=N; if(b<=l||r<=a) return; if(a<=l&&r<=b){ addlazy(k,f); return; } propagate(l,r,k); update(a,b,f,l,(l+r)/2,k*2); update(a,b,f,(l+r)/2,r,k*2+1); val[k] = val[k*2] + val[k*2+1]; } void propagate(int l,int r,int k){ //opr_child -> opr_parent * opr_child parent after child addlazy(k*2 ,lazy[k]); addlazy(k*2+1,lazy[k]); lazy[k] = opr_t::e(); } }; struct handler{ struct val_t{ ll s; int od,ev; val_t(){*this = e();} val_t(ll s_,int od_,int ev_):s(s_),od(od_),ev(ev_){} const static val_t e(){ return val_t(0,0,0); } val_t operator+(const val_t &r) const { return val_t(s+r.s,od+r.od,ev+r.ev); } // friend ostream& operator<<(ostream& o,const val_t& d){return o<e 2 : e->o ll ad; opr_t(){*this = e();} opr_t(int t,ll a):type(t),ad(a){} const static opr_t e(){ return opr_t(0,0); } // friend ostream& operator<<(ostream& o,const opr_t& d){return o< fg f after g if(f.type == 0){ g.ad += f.ad; }else if(f.type == 1){ if((g.type <= 1) ^ (g.ad % 2 == 0)) g = opr_t(2,f.ad); else g = opr_t(1,f.ad); }else{ if((g.type <= 1) ^ (g.ad % 2 == 0)) g = opr_t(1,f.ad); else g = opr_t(2,f.ad); } } static val_t act(const opr_t &f, const val_t &v){ ll n = v.od + v.ev; ll O = v.od, E = v.ev; if((f.type <= 1) ^ (f.ad % 2 == 0)) swap(O,E); ll S = v.s; if(f.type == 0){ S += n * f.ad; }else if(f.type == 1){ S = v.od; S += n * f.ad; }else{ S = v.ev; S += n * f.ad; } return val_t(S,O,E); } }; int main(){ int N,Q; cin >> N >> Q; segtree_lazy seg(N); using opr_t = handler::opr_t; using val_t = handler::val_t; { V v(N); rep(i,N){ ll a; cin >> a; v[i] = val_t(a,a%2==1,a%2==0); } seg = segtree_lazy(v); } rep(_,Q){ int t; cin >> t; if(t == 1){ int l,r; cin >> l >> r; l--; seg.update(l,r,opr_t(1,0)); }else if(t == 2){ int l,r,x; cin >> l >> r >> x; l--; seg.update(l,r,opr_t(0,x)); }else{ int l,r; cin >> l >> r; l--; cout << seg.query(l,r).s << endl; } } }