#include #include #include #include #include using namespace std; using ll = long long; template using vec = vector; template using vvec = vector>; template class SegmentTree{ private: using F = function; int sz; vector seg; const F op;//演算 const Monoid e;//単位元 public: SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){ sz = 1; while(sz0;i--){ seg[i] = op(seg[2*i],seg[2*i+1]); } } void update(int k,const Monoid &x){ k += sz; seg[k] = x; while(k>>=1){ seg[k] = op(seg[2*k],seg[2*k+1]); } } Monoid query(int l,int r){ Monoid L = e,R = e; for(l+=sz,r+=sz;l>=1,r>>=1){ if(l&1) L = op(L,seg[l++]); if(r&1) R = op(seg[--r],R); } return op(L,R); } Monoid operator[](const int &k)const{ return seg[k+sz]; } }; struct state{ ll sum,lsum,rsum,ma; }; constexpr ll inf = 1e18; state op(state& l,state& r){ ll sum,lsum,rsum,ma; sum = l.sum+r.sum; lsum = max(l.lsum,l.sum+r.lsum); rsum = max(r.rsum,r.sum+l.rsum); ma = max(max(l.ma,r.ma),l.rsum+r.lsum); return (state){sum,lsum,rsum,ma}; } int main(){ int N,Q; cin >> N >> Q; SegmentTree seg(N,op,(state){0,-inf,-inf,-inf}); for(int i=0;i> a; seg.set(i,(state){a,a,a,a}); } seg.build(); for(int i=0;i> S; if(S=="set"){ int id; ll val; cin >> id >> val; id--; seg.update(id,(state){val,val,val,val}); }else{ vec L(2),R(2); cin >> L[0] >> L[1] >> R[0] >> R[1]; L[0]--; L[1]--; R[0]--; R[1]--; if(L[1]