Cod sursa(job #9596)

Utilizator Programmer01Mierla Laurentiu Marian Programmer01 Data 27 ianuarie 2007 16:22:06
Problema Secventa 5 Scor 10
Compilator fpc Status done
Runda Unirea 2007, clasele 11-12 Marime 0.81 kb
program p1;
var a,c:array[1..1050000] of int64;
    n,i,j,l,u,k,nr,nr1:longint;
    f:text;
function pivot(i,j:longint):longint;
var di,dj:0..1;
    x,y:longint;
begin
di:=0;
dj:=1;
while i<j do begin
if c[i]>c[j] then begin
x:=c[i];
c[i]:=c[j];
c[j]:=x;
x:=di;
di:=dj;
dj:=x;
end;
i:=i+di;
j:=j-dj;
end;
pivot:=i;
end;
procedure sort(i,j:longint);
var p:longint;
begin
if i<j then begin
p:=pivot(i,j);
sort(i,p-1);
sort(p+1,j);
end;
end;
begin
assign(f,'secv5.in');
reset(f);
readln(f,n,l,u);
for i:=1 to n do
readln(f,a[i]);
close(f);
nr1:=0;
for i:=1 to n do
for j:=i to n do
begin
c[j]:=a[j];
sort(i,j);
nr:=1;
for k:=i+1 to j do
if c[k]<>c[k-1] then nr:=nr+1;
if (nr>=l)and(nr<=u) then nr1:=nr1+1;
end;
assign(f,'secv5.out');
rewrite(f);
write(f,nr1);
close(f);
end.