Pagini recente » Cod sursa (job #2548804) | Cod sursa (job #1994039) | Cod sursa (job #1882592) | Cod sursa (job #1836427) | Cod sursa (job #162877)
Cod sursa(job #162877)
var b,sol:array[1..30001] of integer;
a:array[1..120001] of integer;
i,w,n:longint;
f,g:text;
procedure umplu(i,st,dr:longint);
begin
if (st<=dr) then begin
a[i]:=dr-st+1;
if st<>dr then begin
umplu(i shl 1,st,(st+dr) shr 1);
umplu(i shl 1+1, (st+dr) shr 1+1, dr);
end;
end;
end;
procedure caut(poz,x,st,dr:longint);
begin
if st=dr then begin
a[poz]:=0;
w:=st;
end
else
if a[poz shl 1]< x then begin
dec(a[poz]);
caut(poz shl 1+1,x-a[poz shl 1],(st+dr) shr 1+1, dr);
end
else begin
dec(a[poz]);
caut(poz shl 1, x, st, (st+dr) shr 1);
end;
end;
begin
assign(f,'schi.in'); reset(f);
assign(g,'schi.out'); rewrite(g);
read(f,n);
for i:=1 to n do
read(f,b[i]);
umplu(1,1,n);
for i:=n downto 1 do begin
caut(1,b[i], 1, n);
sol[w]:=i;
end;
for i:=1 to n do
writeln(g,sol[i]);
close(f); close(g);
end.