玄学92求帮助
查看原帖
玄学92求帮助
1081531
Timing703楼主2024/12/1 10:59

不是,洛谷你干嘛嗨嗨you ,这题为啥不给我过?求大佬帮助,我这题是用upper_boundlower_bound写的

不知为什么出现了玄学错误 废话不对说,给代码:

#include<bits/stdc++.h>	//我爱万能头 
using namespace std;
typedef long long ll;
ll n,c,a[200005];	//不开long long 见祖宗 
int ans=0;	
int main(){
	cin >> n >> c;	//输入n和c 
	for(int i=1;i<=n;i++) cin >> a[i]; 	//输入a[i] 
	sort(a+1,a+1+n);	//给a数组排序 
	for(int i=1;i<=n;i++){
		ans += upper_bound(a+1,a+1+n,a[i]+c) - lower_bound(a+1,a+1+n,a[i]+c);
	}
	cout << ans;	//优雅输出 
	return 0;	//结束代码 
}

┏┛墓┗┓

2024/12/1 10:59
加载中...