比赛 |
20111108 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数对的个数 |
最终得分 |
100 |
用户昵称 |
wo shi 刘畅 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-08 10:19:53 |
显示代码纯文本
var
n,c,i,x,t,p:longint;
q,b,a,d:array[0..1000000]of longint;
ans:int64;
procedure sort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=b[(l+r) div 2];
repeat
while b[i]<x do inc(i);
while x<b[j] do dec(j);
if i<=j then
begin
y:=b[i];
b[i]:=b[j];
b[j]:=y;
inc(i);
deC(j);
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
procedure erfen(l,r:longint);
var
mid:longint;
begin
if l=r then
begin
if q[l]=x then p:=l;
exit;
end;
mid:=(l+r) div 2;
if x<=q[mid] then erfen(l,mid)
else erfen(mid+1,r);
end;
begin
assign(input,'dec.in'); reset(input);
assign(output,'dec.out'); rewrite(output);
readln(n,c);
for i:=1 to n do
begin
read(a[i]);
b[i]:=a[i]+c;
end;
sort(1,n);
t:=1;
q[1]:=b[1];
d[1]:=1;
for i:=2 to n do
begin
if b[i]=b[i-1] then inc(d[t])
else begin
inc(t);
q[t]:=b[i];
d[t]:=1;
end;
end;
ans:=0;
for i:=1 to n do
begin
x:=a[i];
p:=0;
erfen(1,t);
if p<>0 then
begin
if c<>0 then inc(ans,d[p])
else inc(ans,d[p]-1);
end;
end;
if c=0 then writeln(ans div 2)
else writeln(ans);
close(input);
close(output);
end.