fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. int main()
  5. {
  6. ios::sync_with_stdio(0);
  7. cin.tie(0);
  8. int T = 1;
  9. cin >> T;
  10. while(T--)
  11. {
  12. int n,l,r;
  13. cin >> n >> l >> r;
  14. vector<int> a(n);
  15. for(auto& i:a) cin >> i;
  16. sort(a.begin(),a.end());
  17. ll ans = 0;
  18. for(int i=0;i<n;i++)
  19. {
  20. int idx = lower_bound(a.begin()+i+1,a.end(),l-a[i])-a.begin();
  21. int idx2 = *upper_bound(a.begin()+i+1,a.end(),r-a[i]);
  22. cout<<idx<<" "<<idx2<<"\n";
  23. //<<idx<<" "<<idx2<<"\n";
  24. ans += idx2-idx;
  25. }
  26. cout << ans << "\n";
  27. }
  28. }
Success #stdin #stdout 0.01s 5284KB
stdin
1
3 4 7
5 1 2
stdout
2  0
2  0
3  0
-7