Cod sursa(job #423387)

Utilizator tomikaBorbath Tamas tomika Data 23 martie 2010 20:26:13
Problema Schi Scor 60
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.04 kb
{
        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..30000] of integer;
var n,k : integer;
	v:tomb;
	arb,poz :tomb;
	g:text;	
function kerek(a:real):integer;
	begin
		if a-trunc(a)<0.5 then kerek:=trunc(a) else 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) and (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;
	constr(1,1,n);
	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.