(几乎一样的题和几乎一样的代码
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 112345; #define LL long long const LL INFF = 0x3f3f3f3f3f3f3f3fll; struct Info{ LL lmax,rmax,sum,val; void maintain(LL x){ lmax=rmax=sum=val=x; } Info(){ maintain(-INFF); sum=0; } }; Info operator + (const Info & a,const Info & b){ Info ret; ret.sum=a.sum+b.sum; ret.lmax=max(a.lmax,a.sum+b.lmax); ret.rmax=max(b.rmax,b.sum+a.rmax); ret.val=max(max(a.val,b.val),a.rmax+b.lmax); return ret; } #define lson o<<1,l,m #define rson o<<1|1,m+1,r #define root 1,1,n #define Now int o,int l,int r #define Mid int m = l + (r-l)/2 Info sarr[maxn*4]; void update(Now,int p,LL v){ if(l==r){ sarr[o].maintain(v); return; } Mid; if(p<=m) update(lson,p,v); else update(rson,p,v); sarr[o]=sarr[o<<1]+sarr[o<<1|1]; } Info query(Now,int ql,int qr){ if(ql<=l && r<=qr){ return sarr[o]; } Mid; Info ret; if(ql<=m) ret = query(lson,ql,qr) + ret; if(m+1<=qr) ret = ret + query(rson,ql,qr); return ret; } int main(){ int n; while(~scanf("%d",&n)){ LL x; for(int i=1;i<=n;i++){ scanf("%lld",&x); update(root,i,x); } int m; scanf("%d",&m); int l,r,p,ord; while(m--){ scanf("%d",&ord); if(ord==1){ scanf("%d %d",&l,&r); printf("%lld\n",query(root,l,r).val); } else{ scanf("%d %lld",&p,&x); update(root,p,x); } } } return 0; }