Cod sursa(job #715175)

Utilizator andreiseiceanSeicean Andrei andreiseicean Data 16 martie 2012 19:37:05
Problema Arbori de intervale Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.75 kb
var a:array[1..131072] of longint;
    n,m,c1,c2,op,el,i:longint;
    f,g:text;
function div_imp(p,q:integer):integer;
var max1,max2,mij:integer;
begin
if p=q then div_imp:=a[p] else
begin
  mij:=(p+q)div 2;
  max1:=div_imp(p,mij);
  max2:=div_imp(mij+1,q);
  if max1>max2 then div_imp:=max1 else div_imp:=max2;
end;
end;
procedure schimb(c,b:longint);
var aux:longint;
begin
aux:=a[b];a[b]:=c;a[c]:=aux;
end;
begin
assign(f,'arbint.in');reset(f);assign(g,'arbint.out');rewrite(g);
read(f,n,m);
for i:=1 to n do
   read(f,a[i]);
for i:=1 to m do
   begin
      read(f,op);
      if op=0 then begin read(f,c1,c2);writeln(g,div_imp(c1,c2)); end
              else begin read(f,c1,c2); schimb(c1,c2); end;
   end;
close(f); close(g);
end.