23tle 8wa求助
查看原帖
23tle 8wa求助
1328426
find_my_dawn楼主2024/3/30 22:24
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+5;
ll a[N];
ll n,c; 
ll find(ll x)
{   ll res=0;
	int h=0,t=n;
	int mid;
	while(h+1!=t)
	{	mid=(h+t)/2;
		if(a[mid]>=x) t=mid;
		else h=mid;
		}	
		if(a[t]==x) return t;
		else return 0;
}
ll find1(ll x,ll tmp)
{   ll res=0;
	for(int i=x;i<=n;i++)
	{
		if(a[i]==tmp) res++;
	}
	return res;
}
int main()
{   ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll ans=0;
	cin>>n>>c;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a,a+n);
	for(int i=n;i>=1;i--)
	{   int tmp=find(a[i]-c);
		if(find(a[i]-c))  ans+=find1(tmp,a[i]-c);
	}
	cout<<ans;
	return 0;
}
```
2024/3/30 22:24
加载中...