Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
2.5 kB
3
Indexable
Never
#include <bits/stdc++.h>
using namespace std;

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'
#define mod %
#define E end()
#define B begin()
#define sz size()
#define em empty()
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>=1;i--)
#define valid(x,y) x>=1 && x<=Row && y>=1 && y<=Col
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
#define accum(v) accumulate(v.B, v.E, 0)
#define sum(n) (((n) * ((n) + 1)) / 2)
#define ll long long
string en="\n";
string sp=" ";
string t="hello";
string Y="YES";
string N="NO";

void solve()
{	
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for (ll i = 0; i < n; i++){
        cin >> v[i];
    }

    sort(v.B, v.E);

    // for (ll i = 0; i < n; i++){
    //     cout << v[i] << sp;
    // }cout << en;
    

    ll ans = 0;
    for (ll i = 0; i < n; i++){
        ll l = i + 1, r = n - 1, m, y = -99;
        while(l <= r) {
            m = (l + r) / 2;
            if(v[i] + v[m] >= a and v[i] + v[m] <= b){
                y = m;
                l = m + 1;
            }
            else if(v[i] + v[m] > b)
                r = m - 1;
            else if(v[i] + v[m] < a)
                l = m + 1;
        }
        l = i + 1, r = y;
        ll x = -99;
        while (l <= r)
        {
            m = (l + r) / 2;
            if (v[i] + v[m] >= a and v[i] + v[m] <= b and m > i)
            {
                x = m;
                r = m - 1;
            }
            else if (v[i] + v[m] < a)
                l = m + 1;
            else if(v[i] + v[m] > b)
                r = m - 1;
        }
        cout << x << "-" << y << sp;
        if(x != -99)
            ans += max(0LL, y - x + 1);
    }
    cout << en;
    cout << ans << en;
}

int main()	
{
    fast;
    int tc = 1; 
    cin >> tc;
    for (ll i = 0; i < tc; i++){
        cout << "Case " << i + 1 << ": ";
        solve();
    }
    
}