记录编号 |
73188 |
评测结果 |
AAAAAAAAAT |
题目名称 |
数对的个数 |
最终得分 |
90 |
用户昵称 |
gungnir |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.002 s |
提交时间 |
2013-10-20 16:50:05 |
内存使用 |
0.93 MiB |
显示代码纯文本
var
a:array[-5..200050] of longint;
y:longint;
x,ans,head,c,tail,ii,i,j,n:longint;
pt:boolean;
procedure qsort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l; j:=r; x:=a[(l+r) div 2];
repeat
while a[j]>x do dec(j);
while a[i]<x do inc(i);
if i<=j then
begin
y:=a[i]; a[i]:=a[j]; a[j]:=y;
inc(i); dec(j);
end;
until i>j;
if i<r then qsort(i,r);
if j>l then qsort(l,j);
end;
procedure find(l,r:longint);
var
mid:longint;
begin
if l>r then exit;
mid:=(l+r) div 2;
if a[mid]=y then begin pt:=true; ii:=mid; exit; end;
if l<>r then
begin
if (a[mid]<y) then find(mid+1,r);
if (a[mid]>y) then find(l,mid-1);
end;
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]);
qsort(1,n);
for i:=1 to n do
begin
x:=a[i]; y:=a[i]-c;
pt:=false;
find(1,i-1);
if pt then
begin
if ii<>i then inc(ans);
head:=ii-1;
tail:=ii+1;
while (a[head]=y) and (head>0) do
begin inc(ans); dec(head); end;
while (a[tail]=y) and (tail<i) do
begin inc(ans); inc(tail); end;
end;
end;
writeln(ans);
close(input); close(output);
end.