Cod sursa(job #341662)

Utilizator ionutz32Ilie Ionut ionutz32 Data 19 august 2009 09:17:50
Problema Arbori de intervale Scor 40
Compilator fpc Status done
Runda Arhiva educationala Marime 1.42 kb
var v:array[1..200000] of longint;
n,m,i,c,d,e,maxim:longint;
f,g:text;
function max(x,y:longint):longint;
         begin
         max:=(x+y+abs(x-y)) shr 1;
         end;
procedure int(nod,a,b:longint);
          var mid:longint;
          begin
          if (d<=a) and (b<=e) then
             begin
             if v[nod]>maxim then
                maxim:=v[nod]
             end
          else
              begin
              mid:=a+(b-a) shr 1;
              if d<=mid then
                 int(nod*2,a,mid);
              if e>mid then
                 int(nod*2+1,mid+1,b);
              end;
          end;
procedure update(nod,a,b:longint);
          var mid:longint;
          begin
          if a=b then
             v[nod]:=e
          else
              begin
              mid:=a+(b-a) shr 1;
              if d<=mid then
                 update(nod*2,a,mid)
              else
                  update(nod*2+1,mid+1,b);
              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 d:=1 to n do
    begin
    read(f,e);
    update(1,1,n);
    end;
for i:=1 to m do
    begin
    readln(f,c,d,e);
    if c=0 then
       begin
       maxim:=0;
       int(1,1,n);
       writeln(g,maxim);
       end
    else
        update(1,1,n);
    end;
close(f);close(g);
end.