fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=998244353;
  5.  
  6. ll count(vector<int> a,int x){
  7. int l=0;
  8. int r=a.size()-1;
  9. ll ans = 0;
  10. while(l<r){
  11. if(a[r]+a[l]<=x){
  12. ans+=r-l;
  13. l++;
  14. }
  15. else r--;
  16. }
  17. return ans;
  18. }
  19.  
  20. void solve() {
  21.  
  22. int n,l,r;
  23. cin >> n >> l >> r;
  24. vector<int> a(n);
  25.  
  26. for(int i=0;i<n;i++) cin >> a[i];
  27. sort(a.begin(),a.end());
  28.  
  29. ll ans = count(a,r)-count(a,l-1);
  30. cout << ans << '\n';
  31. }
  32.  
  33. int main(){
  34. ios::sync_with_stdio(false);
  35. cin.tie(nullptr);
  36.  
  37. int t;
  38. cin >> t;
  39. while (t--) solve();
  40.  
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.01s 5324KB
stdin
4
3 4 7
5 1 2
5 5 8
5 1 2 4 3
4 100 1000
1 1 1 1
5 9 13
2 5 5 1 1
stdout
2
7
0
1