题解:这里用到upper_bound和lower_bound的知识
#include <bits/stdc++.h>
using namespace std;
#define memset(a) memset(a, 0, sizeof(a));
typedef long long int ll;
const int N = 2e6 + 5;
int a[N];
int main()
{
int t;
cin >> t;
while (t--)
{
ll ans = 0;
int n, l, r;
cin >> n >> l >> r;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++)
{
int ll = l - a[i];//表示能够达到的最大值
int rr = r - a[i];
int lsum = lower_bound(a + i + 1, a + n,ll) - a;//最小值
int rsum = upper_bound(a + i + 1, a + n, rr) - a;//最大值+1
ans += rsum - lsum;
}
cout << ans << endl;
}
}