#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } template struct SegmentTree{ using F=function; // private: int sz; vector seg; Monoid query(int a,int b,int k,int l,int r){ if(a<=l and r<=b) return seg[k]; if(b<=l or r<=a) return M0; Monoid L=query(a,b,2*k,l,(l+r)/2); Monoid R=query(a,b,2*k+1,(l+r)/2,r); return f(L,R); } template int find_first(int a,const C &check,Monoid &acc,int k,int l,int r){ if(k>=sz){ acc=f(acc,seg[k]); if(check(acc)) return -1; else return k-sz; } int m=(l+r)/2; if(m<=a) return find_first(a,check,acc,2*k+1,m,r); if(a<=l and check(f(acc,seg[k]))){ acc=f(acc,seg[k]); return -1; } int x=find_first(a,check,acc,2*k+0,l,m); if(x>=0) return x; return find_first(a,check,acc,2*k+1,m,r); } template int find_last(int b,const C &check,Monoid &acc,int k,int l,int r){ if(k>=sz){ acc=f(acc,seg[k]); if(check(acc)) return -1; else return k-sz+1;//ここはfalse, +1した位置はtrue } int m=(l+r)/2; if(b<=m) return find_last(b,check,acc,2*k,l,m); if(r<=b and check(f(acc,seg[k]))){ acc=f(acc,seg[k]); return -1; } int x=find_last(b,check,acc,2*k+1,m,r); if(x>=0) return x; return find_last(b,check,acc,2*k,l,m); } public: F f; Monoid M0;// モノイドの元 SegmentTree(int n,F f,Monoid M0):f(f),M0(M0){ sz=1; while(sz0;k--) seg[k]=f(seg[2*k],seg[2*k+1]); } void update(int k,Monoid x){ k+=sz; seg[k]=x; k>>=1; for(;k;k>>=1) seg[k]=f(seg[2*k],seg[2*k+1]); } Monoid query(int a,int b){ return query(a,b,1,0,sz); } // http://codeforces.com/contest/914/submission/107505449 // max x, check(query(a, x)) = true template int find_first(int a,const C &check){ Monoid val=M0; return find_first(a,check,val,1,0,sz); } // http://codeforces.com/contest/914/submission/107505582 // min x, check(query(x, b)) = true template int find_last(int b,C &check){ Monoid val=M0; return find_last(b,check,val,1,0,sz); } }; template struct sums{ T sum_all,sum_l,sum_r,sum_max; sums():sum_all(0),sum_l(0),sum_r(0),sum_max(0){} sums(T sum_all,T sum_l,T sum_r,T sum_max):sum_all(sum_all),sum_l(sum_l),sum_r(sum_r),sum_max(sum_max){} }; template sums f(sums a,sums b){ sums c; c.sum_all=a.sum_all+b.sum_all; c.sum_l=max(a.sum_l,a.sum_all+b.sum_l); c.sum_r=max(b.sum_r,b.sum_all+a.sum_r); c.sum_max=max({a.sum_max,b.sum_max,a.sum_r+b.sum_l}); return c; } signed main(){ int n,q;cin>>n>>q; using S=sums; SegmentTree seg(n,f,S(0,-LINF,-LINF,-LINF)); rep(i,n){ ll a;cin>>a; seg.set(i,sums(a,a,a,a)); } seg.build(); // rep(k,2*seg.sz) cout<>t; if(t=="set"){ int idx;ll x;cin>>idx>>x;idx--; seg.update(idx,S(x,x,x,x)); }else{ int a,b,c,d;cin>>a>>b>>c>>d;a--,c--; if(c<=a) c=a; if(d<=b) b=d; if(b