数对
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define x first
#define y second
const int N = 1e7 + 10;
map<int,int>m;
int a[N];
int main()
{
int n, k;
cin >> n >>k;
for(int i = 0; i < n; i ++)
{
cin >>a[i];
m[a[i]] ++;
a[i] -= k;
}
LL ans = 0;
for(int i = 0; i < n; i ++)
{
ans += m[a[i]];
}
cout << ans << endl;
return 0;
}

查看10道真题和解析