-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
63 lines (61 loc) · 1.38 KB
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
long long ara[200005];
int main()
{
fastio;
long long t,n,i,high,low,sum,l,r,j;
cin>>t;
while(t--)
{
sum=0;
cin>>n>>l>>r;
for(i=0;i<n;i++)
cin>>ara[i];
sort(ara,ara+n);
for(i=0;i<n;i++)
{
if(i==0)
{
low=n;
high=0;
for(j=1;j<=n;j++)
{
if(ara[i]+ara[j]>=l)
{
low=j;
break;
}
}
for(j=n-1;j>=1;j--)
{
if(ara[i]+ara[j]<=r)
{
high=j;
break;
}
}
}
else
{
if(low<i+1)
low=i+1;
while(ara[i]+ara[low-1]>=l && low>i+1)
{
low--;
}
while(ara[i]+ara[high]>r && high>i)
high--;
}
if(high==i)
break;
if(low==n)
continue;
else
sum+=high-low+1;
}
cout<<sum<<"\n";
}
return 0;
}