Pagini recente » Cod sursa (job #787178) | Cod sursa (job #1002375) | Cod sursa (job #2864984) | Cod sursa (job #3198685) | Cod sursa (job #9779)
Cod sursa(job #9779)
{$q-,r-,s-,d-,i-}
const maxn=1 shl 20;bucata=1 shl 16;modu=bucata-1;zero=ord('0');
var t:Text;
V:array[0..maxn]of longword;
by:array[0..maxn]of word;
A,B:array[0..maxn]of longint;
count:array[0..bucata]of longint;
lg,loc,pas,i,n,la,lb:longint;s:string;
last:longword;
procedure init;
begin
assign(t,'secv5.in');reset(T);readln(t,n,la,lb);
for i:=1 to N do
begin
readln(t,s);
for pas:=1 to length(s) do v[i]:=V[i]*10+ord(s[pas])-zero;
end;close(T);
end;
Procedure Radixsort;
begin
for i:=1 to N do begin by[i]:=V[i]and modu;inc(count[by[i]]);end;
for i:=1 to bucata do inc(count[i],count[i-1]);
for i:=N downto 1 do
begin B[Count[By[i]]]:=i;dec(count[By[i]]);end;
fillchar(count,sizeof(count),0);
for i:=1 to N do begin by[i]:=V[i]shr 16;inc(count[by[i]]);end;
for i:=1 to bucata do inc(count[i],count[i-1]);
for i:=N downto 1 do
begin A[Count[By[B[i]]]]:=B[i];dec(count[By[B[i]]]);end;
end;
var return:int64;
procedure get(limit:longint);
begin
i:=1;lg:=0;
for pas:=1 to N do
begin
while (i<=N)and(lg<=limit)do
begin if A[B[i]]=0 then inc(lg);inc(A[B[i]]);inc(i);end;
inc(return,i-pas);
if lg>limit then dec(return);
dec(A[B[pas]]);
if A[B[pas]]=0 then dec(lg);
end;
end;
begin
init;
radixsort;
lg:=1;last:=V[a[1]];
for i:=1 to N do if V[a[i]]=last then b[A[i]]:=lg else
begin last:=V[A[i]];inc(lg);b[a[i]]:=lg;end;
get(lb);fillchar(a,sizeof(A),0);return:=-return;get(la-1);
assign(t,'secv5.out');rewrite(T);writeln(t,-return);close(T);
end.