- 小白逛公园
- 2015-03-31 15:35:59 @
什么狗血情况???
type tree=record
a,b,l,r,sum:longint;
maxl,maxr,max:longint;
end;
mm=record
maxl,maxr,max,sum:longint;
end;
var a:array[0..1000000]of tree;
i,j,m,n,k,x,y,l,r,tot,t:longint;
s:mm;
procedure make(l,r:longint);
var mid,now:longint;
begin
inc(tot);
a[tot].a:=l;
a[tot].b:=r;
now:=tot;
mid:=(l+r)shr 1;
if l<mid then
begin
a[now].l:=tot+1;
make(l,mid);
a[now].r:=tot+1;
make(mid,r);
end;
end;
function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
procedure change(i,j:longint);
var mid:longint;
begin
if a[i].a=a[i].b-1 then
begin
a[i].sum:=x;
a[i].max:=x;
a[i].maxl:=x;
a[i].maxr:=x;
exit;
end;
mid:=(a[i].a+a[i].b)shr 1;
if j<=mid then change(a[i].l,j)
else change(a[i].r,j);
if (a[a[i].l].maxr<0)and(a[a[i].r].maxl<0) then a[i].max:=max(a[a[i].l].maxr,a[a[i].r].maxl)
else a[i].max:=max(a[a[i].l].maxr,0)+max(a[a[i].r].maxl,0);
a[i].max:=max(a[i].max,max(a[a[i].l].max,a[a[i].r].max));
a[i].maxl:=max(a[a[i].l].maxl,a[a[i].l].sum+a[a[i].r].maxl);
a[i].maxr:=max(a[a[i].r].maxr,a[a[i].r].sum+a[a[i].l].maxr);
a[i].sum:=a[a[i].l].sum+a[a[i].r].sum;
end;
function get(i,l,r:longint):mm;
var mid:longint;
now,s1,s2:mm;
v1,v2:boolean;
begin
v1:=false;v2:=false;
if (l<=a[i].a)and(a[i].b<=r) then
begin
now.maxl:=a[i].maxl;
now.maxr:=a[i].maxr;
now.max:=a[i].max;
now.sum:=a[i].sum;
exit(now);
end;
mid:=(a[i].a+a[i].b)shr 1;
if l<mid then
begin
s1:=get(a[i].l,l,r);
v1:=true;
end;
if mid<r then
begin
s2:=get(a[i].r,l,r);
v2:=true;
end;
if v1 and v2 then
begin
if (s1.maxr<0)and(s2.maxl<0) then now.max:=max(s1.maxr,s2.maxl)
else now.max:=max(s1.maxr,0)+max(s2.maxl,0);
now.max:=max(now.max,max(s1.max,s2.max));
now.maxl:=max(s1.maxl,s1.sum+s2.maxl);
now.maxr:=max(s2.maxr,s2.sum+s1.maxr);
now.sum:=s2.sum+s1.sum;
exit(now);
end
else if v1 then exit(s1)
else exit(s2);
end;
begin
readln(n,m);
make(0,n);
for i:=1 to n do
begin
read(x);
change(1,i);
end;
for i:=1 to m do
begin
readln(k,y,x);
if k=1 then
begin
if y>x then
begin
t:=y;
y:=x;
x:=t;
end;
if (y<=0)or(x>n) then continue;
s:=get(1,y-1,x);
writeln(s.max);
end
else if (y>=1)and(y<=n) then change(1,y);
end;
end.