P1102
  • 板块灌水区
  • 楼主dzzh
  • 当前回复7
  • 已保存回复7
  • 发布时间2024/12/8 14:10
  • 上次更新2024/12/8 17:04:58
查看原帖
P1102
1344890
dzzh楼主2024/12/8 14:10
#include<bits/stdc++.h>
using namespace std;

const int N = 2e5+10;
int n, c, x, ans;
map<int,int> mp;

int main() {
	cin >> n >> c;
	for(int i = 1; i <= n; i++) {
		cin >> x;
		mp[x+c]++;
		if(x-c >= 0) mp[x-c]++;
		if(mp[x] > 0) ans += mp[x];
	}
	cout << ans << endl;
	return 0;
}

为什么会错?

2024/12/8 14:10
加载中...