Cod sursa(job #844223)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 28 decembrie 2012 22:37:07
Problema Schi Scor 65
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.05 kb
{problema schi de pe infoarena}
var a2:array[1..60000]of integer; b,c:array[1..30000]of integer; n,s,v,v2:integer; i:word;
buf1,buf2:array[1..1 shl 15]of char;
procedure interogare(nod,st,dr,a,b:word);
var mij:word;
begin
if (a<=st) and (dr<=b) then s:=s+a2[nod]
else
  begin
    mij:=(dr+st) div 2;
    if a<=mij then interogare(nod*2,st,mij,a,b);
    if b>mij then interogare(nod*2+1,mij+1,dr,a,b);
  end;
end;
procedure scrie(nod,st,dr,a:word);
var mij:word;
begin
  inc(a2[nod]);
  mij:=(st+dr) div 2;
  if mij<>dr then if a<=mij then begin scrie(nod*2,st,mij,a) end
  else scrie(nod*2+1,mij+1,dr,a)
end;
begin
assign(input,'schi.in'); reset(input); settextbuf(input,buf1);
readln(n);
for i:=1 to n do readln(b[i]);
for i:=n downto 1 do
  begin
    v2:=b[i]; v:=1; s:=0;
    interogare(1,1,n,v,v2);
    while s<>0 do begin v:=v2+1; v2:=v2+s; s:=0; interogare(1,1,n,v,v2) end;
    scrie(1,1,n,v2); c[v2]:=i;
  end;
assign(output,'schi.out'); rewrite(output); settextbuf(output,buf2);
for i:=1 to n do writeln(c[i]);
close(output);
end.