# Cod sursa(job #165167)

Utilizator Data 25 martie 2008 17:04:23 Marbles 0 fpc done Arhiva de probleme 1.84 kb
``````var f,g:text;
max,sv,t,t2,k,n,m,i,pi,pj,o,poz:longint;
b,c:array[1..100000] of longint;
col:array[0..64] of longint;
procedure QuickSort(Lo, Hi: longint);
procedure Sort(l, r: longint);
var
i,j,x,y:integer;
begin
i:=l;j:=r;x:=b[(l+r) DIV 2];
repeat
while b[i]<x do i:=i+1;
while x<b[j] do j:=j-1;
if i<=j then
begin
y:=b[i];b[i]:=b[j];b[j]:=y;
y:=c[i];c[i]:=c[j];c[j]:=y;
i:=i+1;j:=j-1;
end;
until i>j;
if l<j then Sort(l,j);
if i<r then Sort(i,r);
end;
begin
sort(Lo,Hi);
end;
function cbinara0(i,st,dr:longint):longint;
begin
poz:=(st+dr) div 2;
if b[poz]=i then cbinara0:=poz
else if st<dr then if i<b[poz] then cbinara0:=cbinara0(i,st,poz-1)
else cbinara0:=cbinara0(i,poz+1,dr);
end;
function cbinara1(i,st,dr:longint):longint;
begin
poz:=(st+dr) div 2;
if (i<=b[poz]) and ((i>b[poz-1]) or (poz=1)) then cbinara1:=poz
else if i<b[poz] then cbinara1:=cbinara1(i,st,poz-1)
else cbinara1:=cbinara1(i,poz+1,dr);
end;
function cbinara2(i,st,dr:longint):longint;
begin
poz:=(st+dr) div 2;
if (i>b[poz]) and ((i<=b[poz+1]) or (poz=n)) then cbinara2:=poz
else if i<b[poz] then cbinara2:=cbinara2(i,st,poz-1)
else cbinara2:=cbinara2(i,poz+1,dr);
end;
begin
assign(f,'marbles.in');reset(f);
assign(g,'marbles.out');rewrite(g);
for i:=1 to n do
quicksort(1,n);
for i:=1 to m do
begin
if o=0 then
begin
sv:=cbinara0(pi,1,n);
b[sv]:=pi+pj;
end
else if o=1 then
begin
t:=cbinara1(pi,1,n);
t2:=cbinara2(pj,1,n);
for k:=0 to 64 do
col[k]:=0;
for k:=t to t2 do
inc(col[c[k]]);
max:=0;
for k:=0 to 64 do
if col[k]>=max then max:=col[k];
writeln(g,max);
end;
end;
close(f);
close(g);
end.

``````