Pagini recente » Cod sursa (job #467841) | Cod sursa (job #1236445) | Cod sursa (job #1462585) | Cod sursa (job #721440) | Cod sursa (job #14943)
Cod sursa(job #14943)
{secventa 5 infoarena unirea 2007}
const maxhash = 1111111;
nmax = 1 shl 20;
type pnod = ^tnod;
tnod = record
old,new:longint;
next:pnod;
end;
lista = record
head,last:pnod;
end;
var sir: array[1..nmax] of longint;
hash : array[0..maxhash] of lista;
frecv: array[1..nmax] of longint;
n,l,u,nrdis:longint;
rez:longint;
procedure addhash(old,neww:longint);
var p : pnod;
poz : longint;
begin
new(p); p^.old:=old; p^.new:=neww; p^.next:=nil;
poz:=old mod maxhash;
if hash[poz].head = nil then
hash[poz].head:=p
else hash[poz].last^.next:=p;
hash[poz].last:=p;
end;
function cautahash(old:longint):longint;
var p:pnod;
poz:longint;
begin
cautahash:=0;
poz:=old mod maxhash;
p:=hash[poz].head;
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):longint;
var i,li:longint;
rez:longint;
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;
procedure citire;
var i,new,x,y:longint;
begin
new:=0;
assign(input,'secv5.in'); reset(input);
readln(n,l,u);
for i:=1 to n do
begin
readln(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.