//segtree by 枳椛明驿墙 #include<bits/stdc++.h> using namespace std; const int N=500001; struct node { int lv,rv,tot,l,r,ans; }tree[N*4]; int n,m; void read(int &x) { int res=0,f=1;char ch; for(;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1; for(;isdigit(ch);ch=getchar()) res=res*10+(ch-'0'); x=res*f; } void pushup(int p) { tree[p].lv=max(tree[p<<1].lv,tree[p<<1].tot+tree[(p<<1)+1].lv); tree[p].rv=max(tree[(p<<1)+1].rv,tree[(p<<1)+1].tot+tree[p<<1].rv); tree[p].tot=tree[p<<1].tot+tree[(p<<1)+1].tot; tree[p].ans=max(tree[p<<1].ans,max(tree[(p<<1)+1].ans,tree[p<<1].rv+tree[(p<<1)+1].lv)); } void build(int l,int r,int p) { tree[p].l=l;tree[p].r=r; if (l==r) { int x;read(x); tree[p].rv=tree[p].lv=tree[p].tot=tree[p].ans=x; return; } int mid=(l+r)>>1; build(l,mid,p<<1);build(mid+1,r,(p<<1)+1); pushup(p); } void updata(int x,int y,int p) { if (tree[p].l==tree[p].r) { tree[p].rv=tree[p].lv=tree[p].tot=tree[p].ans=y; return; } int mid=(tree[p].l+tree[p].r)>>1; if (x<=mid) updata(x,y,p<<1); else updata(x,y,(p<<1)+1); pushup(p); } node query(int x,int y,int p) { if (x<=tree[p].l&&tree[p].r<=y) return tree[p]; int mid=(tree[p].l+tree[p].r)>>1; if (y<=mid) return query(x,y,p<<1); else if (x>mid) return query(x,y,(p<<1)+1); else { node t,t1=query(x,mid,(p<<1)),t2=query(mid+1,y,(p<<1)+1); t.lv=max(t1.lv,t1.tot+t2.lv); t.rv=max(t1.rv+t2.tot,t2.rv); t.tot=t1.tot+t2.tot; t.ans=max(max(t1.ans,t2.ans),t1.rv+t2.lv); return t; } } int main() { read(n);read(m); build(1,n,1); for(int i=1;i<=m;i++) { int k,x,y; read(k);read(x);read(y); if (k==1) { if (x>y) swap(x,y); printf("%dn",query(x,y,1).ans); } if (k==2) { updata(x,y,1); } } return 0; }
|
近期评论