比赛 |
20111108 |
评测结果 |
AAAAAAAAAT |
题目名称 |
数对的个数 |
最终得分 |
90 |
用户昵称 |
reamb |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-08 10:28:00 |
显示代码纯文本
program shuduidegeishu;
var
l,n,c,ans,d,weizhi,i,j:longint;
a:array[1..200000]of longint;
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
j:=j-1;
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
procedure find(x,y:longint);
var
mid:longint;
begin
mid:=(x+y)div 2;
if x=y then
begin
if a[x]=d then
begin
weizhi:=x;
exit
end
else
begin
weizhi:=maxlongint;
exit
end
end;
if a[mid]<d then
find(mid+1,y)
else
find(x,mid)
end;
begin
assign (input,'dec.in');
reset (input);
assign (output,'dec.out');
rewrite (output);
readln(n,c);
for i:=1 to n do
read (a[i]);
a[n+1]:=maxlongint;
sort(1,n);
for i:=1 to n-1 do
begin
d:=a[i]+c;
find(i+1,n);
if weizhi<>maxlongint then
begin
for j:=weizhi to n do
begin
if a[j]<>a[j+1] then
begin
l:=j;
break
end
end;
ans:=ans+l-weizhi+1
end
end;
if c=0 then
begin
ans:=ans*2;
writeln(ans)
end
else
writeln(ans);
close (input);
close (output)
end.