Cod sursa(job #458848)

Utilizator streitferd_erikaStreitferd Erika streitferd_erika Data 26 mai 2010 17:13:33
Problema Arbori de intervale Scor 50
Compilator fpc Status done
Runda Arhiva educationala Marime 1.98 kb
var a:array[1..264000] of longint;
    n,m,i,op,x,y,max,k:longint;
    s:string;

procedure helyettesit(bog,b,j:longint);
var koz:longint;
begin
        if b>=j then
          begin
            a[bog]:=y;
            exit;
          end
                else
          begin
            koz:=(b+j)shr 1;
            if x<=koz then helyettesit((bog shl 1),b,koz)
                     else helyettesit((bog shl 1)+1,koz+1,j);
            if a[bog shl 1]>a[(bog shl 1)+1] then
               a[bog]:=a[(bog shl 1)]
                                             else
               a[bog]:=a[(bog shl 1)+1];
          end;
end;

procedure maximum(bog,b,j:longint);
var koz:longint;
begin
        if (x<=b) and (y>=j) then
           begin
             if max<a[bog] then max:=a[bog];
             exit;
           end
                             else
           begin
             koz:=(b+j) shr 1;
             if x<=koz then maximum(bog shl 1, b, koz);
             if y>koz then maximum((bog shl 1)+1, koz+1, j);
           end;
end;

begin
        assign(input,'arbint.in'); reset(input);
        assign(output,'arbint.out'); rewrite(output);
        readln(n,m);
        y:=0;
        x:=0;
        while (not(eoln(input))) do
          begin
            read(s);
            for k:=1 to length(s) do
              begin
                if s[k]=' ' then
                  begin
                    x:=x+1;
                    helyettesit(1,1,n);
                    y:=0;
                  end
                            else
                  y:=y*10+(ord(s[k])-48);
              end;
          end;
        if s[k]<>' ' then helyettesit(1,1,n);
        for i:=1 to m do
          begin
            read(op,x,y);
            if op=1 then helyettesit(1,1,n)
                    else
              begin
                max:=0;
                maximum(1,1,n);
                writeln(max);
              end;
          end;
        close(output);
end.