#include using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "< void chmax(t&a,u b){if(a void chmin(t&a,u b){if(b using vc=vector; template using vvc=vc>; using pi=pair; using vi=vc; template ostream& operator<<(ostream& os,const pair& p){ return os<<"{"< ostream& operator<<(ostream& os,const vc& v){ os<<"{"; for(auto e:v)os< void print_tuple(ostream&,const T&){ } template void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<(t); print_tuple(os,t); } template ostream& operator<<(ostream&os,const tuple&t){ os<<"{"; print_tuple<0,tuple,Args...>(os,t); return os<<"}"; } void print(ll x,int suc=1){ cout<>i; return i; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=read()+off; return v; } template void print(const vector&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ string s; cin>>s; return s; } template T sq(const T& t){ return t*t; } //#define CAPITAL void yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"< void mkuni(vc&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } ll rand_int(ll l, ll r) { //[l, r] static random_device rd; static mt19937_64 gen(rd()); return uniform_int_distribution(l, r)(gen); } //KUPC2017I //HDU 5306 Gorgeous Sequence template struct segbeats{ vc x; int s; template segbeats(const vc& a){ int n=a.size(); s=1; while(s void chr(int l,int r,int i,int b,int e,F f,Args... args){ if(e<=l||r<=b) return; if(b<=l&&r<=e&&(x[i].*f)(args...)) return; push(i); int m=(l+r)/2; chr(l,m,i*2,b,e,f,args...); chr(m,r,i*2+1,b,e,f,args...); upd(i); } template void ch(int b,int e,F f,Args... args){ assert(b().*F())()) for old-fashioned judges template auto getr(int l,int r,int i,int b,int e,F f,G g,H h){ if(e<=l||r<=b) return h; if(b<=l&&r<=e) return (x[i].*f)(); push(i); int m=(l+r)/2; return g(getr(l,m,i*2,b,e,f,g,h),getr(m,r,i*2+1,b,e,f,g,h)); } template auto get(int b,int e,F f,G g,H h){ assert(b pair findr(int i,int l,int r,int b,int e,F f,Args&...args){ if(e<=l||r<=b)return {e,N()}; if(b<=l&&r<=e){ if(!(x[i].*f)(args...))return {e,N()}; if(r-l==1)return {l,x[i]}; } push(i); int m=(l+r)/2; auto a=findr(i*2,l,m,b,e,f,args...); if(a.a pair find(int b,int e,F f,Args&...args){ assert(b pair findr(int i,int l,int r,int b,int e,F f,Args&&...args){ if(e<=l||r<=b)return {b-1,N()}; if(b<=l&&r<=e){ if(!(x[i].*f)(args...))return {b-1,N()}; if(r-l==1)return {l,x[i]}; } push(i); int m=(l+r)/2; auto a=findr(i*2+1,m,r,b,e,f,forward(args)...); if(a.a>=b)return a; return findr(i*2,l,m,b,e,f,forward(args)...); } template pair find(int b,int e,F f,Args&&...args){ assert(b(args)...); } */ }; //usage struct N{ int l1,l2,a,b,num,sum; N(int v=0):l1(-1),l2(0),a(!(v%2)),b(v%2),num(1),sum(v){} bool add(int v){ l2+=v; if(v%2)swap(a,b); sum+=num*v; return true; } bool mod(){ l1=(l2+l1==-1?0:l1)%2; l2=0; sum=b; return true; } void push(N& x,N& y){ if(l1!=-1){ x.add(l1); x.mod(); y.add(l1); y.mod(); l1=-1; } x.add(l2); y.add(l2); l2=0; } static N merge(N x,N y){ N res; res.a=x.a+y.a; res.b=x.b+y.b; res.num=x.num+y.num; res.sum=x.sum+y.sum; return res; } int gets(){ return sum; } }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<>n>>q; vi a=readvi(n); segbeats seg(a); rep(_,q){ int t,l,r;cin>>t>>l>>r; l--; if(t==1){ seg.ch(l,r,&N::mod); }else if(t==2){ int x;cin>>x; seg.ch(l,r,&N::add,x); }else{ print(seg.get(l,r,&N::gets,[](int x,int y){return x+y;},int(0))); } } }