#include using namespace std; #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define abs(a) max((a),-(a)) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repe(i,n) rep(i,(n)+1) #define per(i,n) for(int i=(int)(n)-1;i>=0;i--) #define pere(i,n) rep(i,(n)+1) #define all(x) (x).begin(),(x).end() #define SP <<" "<< #define RET return 0 #define MOD 1000000007 #define INF 1000000000000000 typedef long long LL; typedef long double LD; struct LazySegmentTree { private: int n; vector maxnode, minnode, maxrange, lazy, a; public: LazySegmentTree(vector v) { a=v; int sz = (int)v.size()+1; n = 1; while(n < sz) n *= 2; maxnode.resize(2*n-1,-INF); minnode.resize(2*n-1,INF); maxrange.resize(2*n-1,-INF); lazy.resize(2*n-1, 0); maxnode[n-1]=minnode[n-1]=0; for(int i=1; i=0; i--){ maxnode[i] = max(maxnode[i*2+1],maxnode[i*2+2]); minnode[i] = min(minnode[i*2+1],minnode[i*2+2]); maxrange[i] = max(max(maxrange[i*2+1],maxrange[i*2+2]),maxnode[i*2+2]-minnode[i*2+1]); } } void disp(){ for(int i=0;i 1) { lazy[2*k+1] += lazy[k]; lazy[2*k+2] += lazy[k]; } lazy[k] = 0; } } void set(int id, LL x){ add(id+1,n,x-a[id]); a[id]=x; } void add(int a, int b, LL x, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] += x; eval(k, l, r); }else{ add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r); maxnode[k]=max(maxnode[2*k+1],maxnode[2*k+2]); minnode[k]=min(minnode[2*k+1],minnode[2*k+2]); maxrange[k]=max(max(maxrange[k*2+1],maxrange[k*2+2]),maxnode[k*2+2]-minnode[k*2+1]); } } LL getmin(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; if(b <= l || r <= a) return INF; eval(k, l, r); if(a <= l && r <= b) return minnode[k]; LL vl = getmin(a, b, 2*k+1, l, (l+r)/2); LL vr = getmin(a, b, 2*k+2, (l+r)/2, r); return min(vl,vr); } LL getmax(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; if(b <= l || r <= a) return -INF; eval(k, l, r); if(a <= l && r <= b) return maxnode[k]; LL vl = getmax(a, b, 2*k+1, l, (l+r)/2); LL vr = getmax(a, b, 2*k+2, (l+r)/2, r); return max(vl,vr); } LL getmaxrange(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = n; if(b <= l || r <= a) return -INF; eval(k, l, r); if(a <= l && r <= b) return maxrange[k]; LL vl = getmaxrange(a, b, 2*k+1, l, (l+r)/2); LL vr = getmaxrange(a, b, 2*k+2, (l+r)/2, r); return max(max(vl,vr),getmax(a, b, 2*k+2, (l+r)/2, r)-getmin(a, b, 2*k+1, l, (l+r)/2)); } }; int main(){ int n,q; cin >> n >> q; vector a(n); for(int i=0;i> a[i]; LazySegmentTree seg(a); seg.disp(); string s; for(int t=0;t> s; if(s=="set"){ int id,x; cin >> id >> x; id--; seg.set(id,x); }else{ int l1,l2,r1,r2; cin >> l1 >> l2 >> r1 >> r2; l1--,l2--,r1--,r2--; r1=max(r1,l1); l2=min(l2,r2); // cout << l1 SP l2 SP r1 SP r2 << endl; if(l2