Pagini recente » Cod sursa (job #3248672) | Cod sursa (job #2162604) | Cod sursa (job #43118) | Cod sursa (job #2589557) | Cod sursa (job #43957)
Cod sursa(job #43957)
var free:array[1..65536] of word;
v,el:array[1..32768] of word;
f:text;
k,n,i,ok:word;
procedure constr(i,n:word);
begin
if n>0 then
begin
free[i]:=n;
if n>1 then
begin
constr(2*i,n div 2+n mod 2);
constr(2*i+1,n div 2);
end;
end;
end;
procedure cauta(i,n,x,y:word);
var mij:word;
begin
if x=y then el[x]:=k
else
begin
mij:=x+(y-x+1)div 2+ (y-x+1) mod 2-1;
if free[2*i]>=n then cauta(2*i,n,x,mij)
else cauta(2*i+1,n-free[2*i],mij+1,y);
end;
dec(free[i]);
end;
begin
assign(f,'schi.in'); reset(f);
readln(f,n);
for i:=1 to n do readln(f,v[i]);
close(f);
constr(1,n);
for k:=n downto 1 do
begin
cauta(1,v[k],1,n);
end;
assign(f,'schi.out'); rewrite(f);
for i:=1 to n do
writeln(f,el[i]);
close(f);
end.