#include using namespace std; using Int = long long; const char newl = '\n'; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a void drop(const T &x){cout< vector read(size_t n){ vector ts(n); for(size_t i=0;i>ts[i]; return ts; } template struct RBST{ using u32 = uint32_t; u32 xor128(){ static u32 x = 123456789; static u32 y = 362436069; static u32 z = 521288629; static u32 w = 88675123; u32 t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } alignas(Node) static inline char pool[sizeof(Node)*LIM]; static inline Node* ptr = (Node*)pool; static inline size_t size; template inline Node* create(Args&&... args){ return new (ptr+size++) Node(std::forward(args)...); } inline size_t count(const Node *t){return Data::count(t);} inline Node* touch(Node *t){ return static_cast(this)->touch(t); } inline void toggle(Node *t){ return static_cast(this)->toggle(t); } inline Node* pushup(Node *t){ return static_cast(this)->pushup(t); } Node* toggle(Node *a,size_t l,size_t r){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=touch(t.first); toggle(u); return merge(s.first,merge(u,t.second)); } Node* merge(Node* a,Node* b){ if(a==nullptr) return b; if(b==nullptr) return a; if(xor128()%(count(a)+count(b))r=merge(a->r,b); a->r->p=a; return pushup(a); } b=touch(b); b->l=merge(a,b->l); b->l->p=b; return pushup(b); } pair split(Node* a,size_t k){ if(a==nullptr) return make_pair(a,a); a=touch(a); if(k<=count(a->l)){ if(a->l) a->l->p=nullptr; auto s=split(a->l,k); a->l=s.second; if(a->l) a->l->p=a; return make_pair(s.first,pushup(a)); } if(a->r) a->r->p=nullptr; auto s=split(a->r,k-(count(a->l)+1)); a->r=s.first; if(a->r) a->r->p=a; return make_pair(pushup(a),s.second); } Node* insert(Node *a,size_t k,Node v){ Node* b=create(v); auto s=split(a,k); return merge(merge(s.first,b),s.second); } Node* erase(Node *a,size_t k){ assert(kl); if(kl,k); if(k>num) return find_by_order(a->r,k-(num+1)); return a; } inline bool is_right(Node* a){ return a->p and a->p->r==a; } size_t order_of_key(Node* a){ size_t res=count(a->l); while(a){ if(is_right(a)) res+=count(a->p->l)+1; a=a->p; } return res; } Node* build(size_t l,size_t r,const vector &vs){ if(l+1==r) return create(vs[l]); size_t m=(l+r)>>1; return merge(build(l,m,vs),build(m,r,vs)); } Node* build(const vector &vs){ return build(0,vs.size(),vs); } template Node* set_val(Node *a,size_t k,T val){ assert(kl); if(kl=set_val(a->l,k,val); if(k>num) a->r=set_val(a->r,k-(num+1),val); if(k==num) a->val=val; return pushup(a); } Node* get_val(Node *a,size_t k){ assert(kl); if(kl,k); if(k>num) return get_val(a->r,k-(num+1)); return a; } template Node* update(Node *a,size_t l,size_t r,E v){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=touch(t.first); static_cast(this)->propagate(u,v); return merge(s.first,merge(u,t.second)); } decltype(auto) query(Node *&a,size_t l,size_t r){ auto s=split(a,l); auto t=split(s.second,r-l); auto u=t.first; auto res=static_cast(this)->query(u); a=merge(s.first,merge(u,t.second)); return res; } }; template struct Ushi{ F f; Flip flip; T ti; Ushi(F f,Flip flip,T ti):f(f),flip(flip),ti(ti){} struct Node{ Node *l,*r,*p; size_t cnt; bool rev; T val,dat; Node(T val): cnt(1),rev(0),val(val),dat(val){l=r=p=nullptr;} }; static inline size_t count(const Node *t){ return t?t->cnt:0; } inline void toggle(Node *t){ swap(t->l,t->r); t->val=flip(t->val); t->dat=flip(t->dat); t->rev^=1; } inline bool dirty(Node *t){ return t->rev; } inline Node* eval(Node* t){ if(t->rev){ if(t->l) toggle(t->l); if(t->r) toggle(t->r); t->rev=false; } return t; } inline Node* pushup(Node *t){ t->cnt=count(t->l)+1+count(t->r); t->dat=t->val; if(t->l) t->dat=f(t->l->dat,t->dat); if(t->r) t->dat=f(t->dat,t->r->dat); return t; } inline T get_val(Node *t){ assert(t); return t->val; } inline T reflect(Node *t){ assert(t); return t->dat; } void dump(typename vector::iterator it,Node* const t,bool rev){ if(!count(t)) return; Node *l=t->l,*r=t->r; if(rev) swap(l,r); rev^=t->rev; dump(it,l,rev); *(it+count(l))=Node(t->val); dump(it+count(l)+1,r,rev); } vector dump(Node* t){ assert(t!=nullptr); vector vs(count(t),*t); dump(vs.begin(),t,false); return vs; } }; template struct Basic : RBST, Data, typename Data::Node, LIM>{ using super = RBST; using Node = typename Data::Node; Data data; template Basic(Args... args):data(forward(args)...){} inline Node* touch(Node *t){return data.eval(t);} using super::toggle; inline void toggle(Node *t){return data.toggle(t);} template inline void propagate(Node *t,E x){return data.propagate(t,x);} inline Node* pushup(Node *t){return data.pushup(t);} inline decltype(auto) get_val(Node *a,size_t k){ return data.get_val(super::get_val(a,k)); } using super::query; inline decltype(auto) query(Node *a){ return data.reflect(a); } }; //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n,q; cin>>n>>q; auto as=read(n); using ll = long long; auto f=[&](ll a,ll b){return a+b;}; auto flip=[&](ll a){return a;}; using Data = Ushi; using Node = Data::Node; const size_t LIM = 3e6; Basic G(f,flip,0); auto A=G.build(vector(as.begin(),as.end())); for(int i=0;i>t>>l>>r; l--; ll sum=G.query(A,l,r); if(t==1){ auto [x,y]=G.split(A,r); auto [p,q]=G.split(x,l); A=G.merge(G.merge(p,G.create(sum)),y); } if(t==2) cout<