Cod sursa(job #167993)

Utilizator free2infiltrateNezbeda Harald free2infiltrate Data 30 martie 2008 15:11:43
Problema Arbori de intervale Scor 40
Compilator fpc Status done
Runda Arhiva educationala Marime 1.35 kb
var A : array [1..100000] of longint;
    m,n,i,j,x,i1,i2,max : longint;

function maxim(x,y:longint):longint;
begin
if x>y then maxim := x
        else maxim := y;
end;

procedure update(ni,st,dr,poz,x:longint);
var mij : longint;
begin

if st=dr then A[ni] := x
else begin
        mij := (st+dr) div 2;
        if poz<=mij then update(2*ni,st,mij,poz,x)
                    else update(2*ni+1,mij+1,dr,poz,x);
        if A[2*ni]>A[2*ni+1] then A[ni] := A[2*ni]
                             else A[ni] := A[2*ni+1];
        end;
end;

procedure caut(ni,st,dr,goi,gof: longint);
var mij : longint;
begin
if (goi<=st)and(dr<=gof) then
                           if max<A[ni] then max := A[ni]
                           else
else
begin
     mij := (st+dr) div 2;
     if (goi<=mij) then caut(2*ni,st,mij,goi,gof);
     if (mij<gof) then caut(2*ni+1,mij+1,dr,goi,gof);
end;
end;


begin
assign(input,'arbint.in');
reset(input);
assign(output,'arbint.out');
rewrite(output);

readln(n,m);

for i := 1 to n do begin
         read(x);
         update(1,1,n,i,x);
         end;


readln;


for i := 1 to m do begin
readln(x,i1,i2);
if x=0 then begin
            max := 0;
            caut(1,1,N,i1,i2);
            writeln(max);
            end
else update(1,1,N,i1,i2);

end;



close(input);
close(output);


end.