Time Limit: 330MS |
|
Memory Limit: 1572864KB |
|
64bit IO Format: %lld &%llu |
Description
You are given a sequence a of n (n <= 50000) integers between-10000 and 10000. On the sequence you has to apply m (m <= 50000) operations:
Modify the i-th element in the sequence or for given x y print Max{ai + ai+1 +: + Aj | x<=i<=j<=y}.
Input
The first line of input contains an integer N. The following line contains N integers, representing the sequence A1. An.
The third line contains an integer M. The next M lines contain the operations in following form:
0 x y:modify Ax into Y (|y|<=10000).
1 x y:print Max{ai + ai+1 +: + Aj | x<=i<=j<=y}.
Output
For each query, print an integer as the problem required.
Example
Input:2 3 441 1 3-31 2 3 3Output:64-3
Hint
Added by: |
Bin Jin |
Date: |
2007-08-03 |
Time limit: |
0.330s |
Source limit: |
5000B |
Memory limit: |
1536MB |
Cluster: |
Cube (Intel G860) |
Languages: |
All except:c++ 5 |
Resource: |
Own problem |
Single-point modification, asking for the maximum number of consecutive fields in the interval.
@TYVJ P1427 Little White stroll the park
1 /*by Silvern*/2#include <algorithm>3#include <iostream>4#include <cstring>5#include <cstdio>6#include <cmath>7 #defineLC Rt<<18 #defineRC Rt<<1|19 using namespacestd;Ten Const intmxn=100010; One intRead () { A intx=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} the returnx*F; - } - intn,m; - intDATA[MXN]; + structnode{ - intMX; + intML,MR; A intSMM; at}t[mxn<<2],tmp0; - voidPUSH_UP (intLintRintRT) { -t[rt].smm=t[lc].smm+t[rc].smm; -t[rt].mx=Max (t[lc].mx,t[rc].mx); -T[rt].mx=max (t[lc].mr+t[rc].ml,t[rt].mx); -T[rt].ml=max (t[lc].ml,t[lc].smm+t[rc].ml); inT[rt].mr=max (t[rc].mr,t[rc].smm+t[lc].mr); - return; to } + voidBuild (intLintRintRT) { - if(L==R) {T[rt].mx=t[rt].ml=t[rt].mr=data[l];t[rt].smm=data[l];return;} the intMid= (l+r) >>1; * Build (L,MID,LC); $Build (mid+1, R,RC);Panax Notoginseng push_up (L,R,RT); - return; the } + voidChangeintPintVintLintRintRT) { A if(l==R) { the if(p==l) {t[rt].ml=t[rt].mr=t[rt].mx=t[rt].smm=v;} + return; - } $ intMid= (l+r) >>1; $ if(p<=mid) Change (P,V,L,MID,LC); - ElseChange (p,v,mid+1, R,RC); - push_up (L,R,RT); the return; - }WuyiNode Query (intLintRintLintRintRT) { the //printf ("%d%d%d%d\n", l,r,l,r,rt); - if(L<=l && r<=r) {returnt[rt];} Wu intMid= (l+r) >>1; - node res1; About if(L<=mid) res1=query (L,R,L,MID,LC); $ Elseres1=tmp0; - node Res2; - if(R>mid) Res2=query (l,r,mid+1, R,RC); - ElseRes2=tmp0; ANode res={0}; +res.smm=res1.smm+res2.smm; theres.mx=Max (res1.mx,res2.mx); -Res.mx=max (res.mx,res1.mr+res2.ml); $Res.ml=max (res1.ml,res1.smm+res2.ml); theRes.mr=max (res2.mr,res2.smm+res1.mr); the returnRes; the } the intMain () { -n=read (); in inti,j,x,y,k; the for(i=1; i<=n;i++) data[i]=read (); theBuild (1N1); Abouttmp0.ml=tmp0.mr=tmp0.mx=-1e9;tmp0.smm=0; them=read (); the for(i=1; i<=m;i++){ theK=read (); X=read (); y=read (); + if(k) { - if(x>y) Swap (x, y); theprintf"%d\n", query (x, Y,1N1). mx);Bayi } the ElseChange (x, Y,1N1); the } - return 0; -}
Spoj GSS3 Can You answer these queries III