链接:https://codeforces.com/contest/1538/problem/C
大意:查找有多少对ai与aj之和在区间[l,r];
每一个a[i]查找在小于a[i]的范围中有多少个数满足这个条件即可。
#include <bits/stdc++.h>
using namespace std;
/*#define rapido
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#define endl "n"*/
#define bug(x) cout<<#x<<" == "<<x<<'n'
#define ll long long
const int MAX_N=1e6;
ll a[MAX_N]={ 0 };
int32_t main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int l,r;
scanf("%d %d",&l,&r);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a[i]);
}
sort(a+1,a+1+n);
ll ans=0;
for(int i=1;i<=n;i++)
{
ans+=upper_bound(a+1,a+i,r-a[i])-lower_bound(a+1,a+i,l-a[i]);
}
printf("%lldn",ans);
}
}
最后
以上就是开心裙子最近收集整理的关于Number of Pairs(思维)的全部内容,更多相关Number内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复