Mai intai trebuie sa te autentifici.
Cod sursa(job #144482)
Utilizator | Data | 27 februarie 2008 18:33:28 | |
---|---|---|---|
Problema | Schi | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva de probleme | Marime | 1.05 kb |
var arb,v,rez:array[0..40000] of longint;
n,i,j,t,poz,log:longint;
procedure build(nod:longint;l,r:longint);
var m:longint;
begin
if (l=r) then
begin
arb[nod]:=1;
exit;
end;
m:=(l+r) div 2;
build(nod*2,l,m);
build(nod*2+1,m+1,r);
arb[nod]:=arb[2*nod]+arb[2*nod+1];
end;
procedure compute(nod,x:longint;var poz:longint);
var m:longint;
begin
if (arb[nod]=1)and(nod>log) then
begin
poz:=nod-log;
arb[nod]:=0;
exit;
end;
if x<=arb[2*nod] then
compute(2*nod,x,poz)
else
compute(2*nod+1,x-arb[2*nod],poz);
dec(arb[nod]);
end;
begin
assign(input,'schi.in');reset(input);
assign(output,'schi.out');rewrite(output);
readln(n);
for i:=1 to n do
read(v[i]);
log:=1;
while log*2<n do
log:=log*2;
log:=log*2-1;
build(1,1,n);
for i:=n downto 1 do
begin
t:=v[i];
poz:=0;
compute(1,t,poz);
rez[poz]:=i;
end;
for i:=1 to n do
writeln(rez[i]);
close(input);close(output);
end.