Pagini recente » Cod sursa (job #1638305) | Cod sursa (job #1318356) | Cod sursa (job #47652) | Cod sursa (job #2686635) | Cod sursa (job #47650)
Cod sursa(job #47650)
{secventa 5 infoarena unirea 2007}
const maxhash = 1111111;
nmax = 1 shl 20;
type pnod = ^tnod;
tnod = record
old,new:longword;
next:pnod;
end;
var sir: array[1..nmax] of longword;
hash : array[0..maxhash] of pnod;
frecv: array[1..nmax] of longint;
n,l,u,nrdis:longint;
rez:longint;
c:char;
f:text;
procedure addhash(old:longword; neww:longint);
var p : pnod;
poz : longint;
begin
poz:=old mod maxhash;
new(p); p^.old:=old; p^.new:=neww; p^.next:=hash[poz];
hash[poz]:=p;
end;
function cautahash(old:longword):longint;
var p:pnod;
poz:longint;
begin
cautahash:=0;
poz:=old mod maxhash;
p:=hash[poz];
while p <> nil do
begin
if p^.old = old then
begin
cautahash:=p^.new;
break;
end;
p:=p^.next;
end;
end;
function calc(x:longint):int64;
var i,li:longint;
rez:int64;
begin
fillchar(frecv,sizeof(frecv),0);
nrdis:=0; rez:=0;
li:=1;
for i:=1 to n do
begin
if frecv[sir[i]] = 0 then
begin
frecv[sir[i]]:=1;
inc(nrdis);
end
else inc(frecv[sir[i]]);
while nrdis > x do
begin
dec(frecv[sir[li]]);
if frecv[sir[li]] = 0 then dec(nrdis);
inc(li);
end;
rez:=rez+(i-li+1);
end;
calc:=rez;
end;
function getnn:longword;
var rez:longword;
begin
rez:=0;
while ((ord(c) >=48) and (ord(c) <= 57)) do
begin
rez:=rez*10 + ord(c) - 48;
read(f,c);
end;
getnn:=rez;
while (((ord(c) < 48) or ( ord(c) > 57))) and ( ord(c) <> 26) and ( c <> '-') do
read(f,c);
end;
procedure citire;
var i,new,y:longint;
x:longword;
buf: array[1..32768] of byte;
begin
new:=0;
assign(f,'secv5.in'); reset(f); settextbuf(f,buf);
readln(f,n,l,u);
for i:=1 to n do
begin
readln(f,x);
y:=cautahash(x);
if y <> 0 then sir[i]:=y
else
begin
inc(new);
addhash(x,new);
sir[i]:=new;
end;
end;
close(input);
end;
begin
citire;
assign(output,'secv5.out'); rewrite(output);
writeln(calc(u)-calc(l-1));
close(output);
end.