Pagini recente » Cod sursa (job #2624602) | Cod sursa (job #423427)
Cod sursa(job #423427)
{
schi3.pas
Copyright 2010 Borbath Tamas <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
}
program schi;
uses crt;
type tomb=array[1..65000] of integer;
var n,k : integer;
v:tomb;
arb,poz :tomb;
g:text;
function kerek(a:real):integer;
begin
kerek:=trunc(a)+1;
end;
procedure beolvas;
var i:integer;
f:text;
begin
assign(f,'schi.in');
reset(f);
readln(f,n);
for i:=1 to n do
readln(f,v[i]);
end;
procedure update(nod, st, dr, pozitie:integer; loc:integer);
var mij:integer;
begin
dec(arb[nod]);
if (st=dr) then begin
poz[st]:=pozitie;
end else
begin
mij:=trunc((st+dr)/2);
if (arb[2*nod]>=loc) then update(2*nod,st,mij,pozitie,loc)
else begin
loc:=loc-arb[2*nod];
update(((2*nod)+1),(mij+1),dr,pozitie,loc);
end;
end;
end;
procedure constr(nod,st,dr:integer);
var mij:integer;
begin
arb[nod]:=dr-st+1;
if (st<>dr) then begin
mij:=trunc((st+dr)/2);
//writeln(mij);
constr(2*nod,st,mij);
constr(2*nod+1,mij+1,dr);
end;
end;
BEGIN
beolvas;
//writeln('n=',n);
constr(1,1,n);
for k:=1 to n do
writeln(arb[k]);
writeln('vege');
for k:=n downto 1 do
begin
update(1,1,n,k,v[k]);
end;
assign(g,'schi.out');
rewrite(g);
for k:=1 to n do
writeln(g,poz[k]);
close(g);
END.