Cod sursa(job #341535)

Utilizator ionutz32Ilie Ionut ionutz32 Data 18 august 2009 17:27:01
Problema Arbori de intervale Scor 30
Compilator fpc Status done
Runda Arhiva educationala Marime 1.74 kb
var v,u:array[1..1036000] of int64;
n,m,i,c,d:longint;
e,maxim:int64;
f,g:text;
function max(x,y:int64):int64;
         begin
         if x>y then
            max:=x
         else
             max:=y;
         end;
procedure cmp(p,a,b:longint);
          begin
          if a<>b then
             begin
             cmp(p*2,a,a+(b-a) div 2);
             cmp(p*2+1,a+(b-a) div 2+1,b);
             v[p]:=max(v[p*2],v[p*2+1]);
             end
          else
              v[p]:=u[a];
          end;
procedure int(nod,a,b,lo,hi:longint);
          begin
          if (lo<=a) and (b<=hi) then
             begin
             if v[nod]>maxim then
                maxim:=v[nod]
             end
          else
              begin
              if lo<=a+(b-a) div 2 then
                 int(nod*2,a,a+(b-a) div 2,lo,hi);
              if hi>a+(b-a) div 2 then
                 int(nod*2+1,a+(b-a) div 2+1,b,lo,hi);
              end;
          end;
procedure update(nod,a,b:longint;val:int64);
          begin
          if (a=val) and (b=val) then
             v[nod]:=e
          else
              begin
              if val<=a+(b-a) div 2 then
                 update(nod*2,a,a+(b-a) div 2,val)
              else
                  update(nod*2+1,a+(b-a) div 2+1,b,val);
              v[nod]:=max(v[nod*2],v[nod*2+1]);
              end;
          end;
begin
assign(f,'arbint.in');
assign(g,'arbint.out');
reset(f);rewrite(g);
readln(f,n,m);
for i:=1 to n do
    read(f,u[i]);
cmp(1,1,n);
for i:=1 to m do
    begin
    readln(f,c,d,e);
    if c=0 then
       begin
       maxim:=u[d];
       int(1,1,n,d,e);
       writeln(g,maxim);
       end
    else
        update(1,1,n,d);
    end;
close(f);close(g);
end.