#include #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef tuple Pll; typedef vector vll; const ll INF = LLONG_MAX/10; const ll MOD = 1e9+7; template struct SegmentTree{ using F = function; int n; F f; T ti; vector dat; SegmentTree(){}; SegmentTree(F f,T ti):f(f),ti(ti){} void init(int n_){ n=1; while(n &v){ int n_=v.size(); init(n_); for(int i=0;i>=1) dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]); } //[a,b) T query(int a,int b){ T vl=ti,vr=ti; for(int l=a+n,r=b+n;l>=1,r>>=1) { if(l&1) vl=f(vl,dat[l++]); if(r&1) vr=f(dat[--r],vr); } return f(vl,vr); } T operator[](const int &k) const {return dat[k + n];} }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,Q;cin>>N>>Q; using hoge=tuple; auto f=[](hoge a,hoge b){ ll asum,amax,al,ar; ll bsum,bmax,bl,br; tie(asum,amax,al,ar)=a; tie(bsum,bmax,bl,br)=b; ll csum,cmax,cl,cr; csum = asum+bsum; cmax = max({amax,bmax,ar+bl}); cl = max(al,asum+bl); cr = max(ar+bsum,br); return make_tuple(csum,cmax,cl,cr); }; SegmentTree seg(f,make_tuple(0,-INF,-INF,-INF)); seg.init(N); vll a(N); for(ll i=0;i>a[i]; seg.set_val(i,make_tuple(a[i],a[i],a[i],a[i])); } for(ll q=0;q>op; if(op[0]=='s'){ ll i,x;cin>>i>>x;i--; seg.set_val(i,make_tuple(x,x,x,x)); a[i]=x; }else{ ll l1,l2,r1,r2;cin>>l1>>l2>>r1>>r2; l1--;l2--;r1--;r2--; ll ans=0; if(l2(l)+get<0>(m)+get<2>(r); }else if(r1<=l1){ if(l2<=r2){ hoge m=seg.query(l1,l2+1); hoge r=seg.query(l2,r2+1); ans = max(get<1>(m),get<3>(m)+get<2>(r)-a[l2]); }else{ hoge m=seg.query(l1,r2+1); ans = get<1>(m); } }else{ if(r2<=l2){ hoge l=seg.query(l1,r1+1); hoge m=seg.query(r1,r2+1); ans = max(get<1>(m),get<3>(l)+get<2>(m)-a[r1]); }else{ hoge l=seg.query(l1,r1+1); hoge m=seg.query(r1,l2+1); hoge r=seg.query(l2,r2+1); ans = get<1>(m); ans = max(ans,get<3>(l)+get<2>(m)-a[r1]); ans = max(ans,get<3>(m)+get<2>(r)-a[l2]); ans = max(ans,get<3>(l)+get<0>(m)+get<2>(r)-a[r1]-a[l2]); } } cout<