258052026-03-03 17:06:28anonTiltott pár (45 pont)cpp17Wrong answer 29/45218ms2516 KiB
#include <bits/stdc++.h>
#define sz(x) ((ll) (x).size())
#define all(x) (x).begin(), (x).end()
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
int main() {
    FastIO;
    ll N;
    cin>>N;
    vector<array<ll,2>>A(N);
    for(ll i=0;i<N;i++){
        cin>>A[i][0];
        A[i][1]=i;
    }
    sort(all(A));
    ll Q;
    cin>>Q;
    while(Q--){
        ll X,Y;
        cin>>Y>>X;
        array<ll,2>q;
        q[0]=X;
        q[1]=0;
        ll xbeg=lower_bound(all(A),q)-A.begin();
        q[1]=N;
        ll xend=lower_bound(all(A),q)-A.begin();
        ll xlo=0;
        ll xhi=xend-xbeg;
        ll xc=xhi;
        if(!xc){
            cout<<"0\n";
            continue;
        }
        q[0]=Y;
        q[1]=0;
        ll ybeg=lower_bound(all(A),q)-A.begin();
        q[1]=N;
        ll yend=lower_bound(all(A),q)-A.begin();
        ll ylo=0;
        ll yhi=yend-ybeg;
        ll lo=0;
        ll hi=N;
        ll ans=0;
        while(lo+1<hi){
            ll mid=(lo+hi)>>1;
            q[0]=X;
            q[1]=mid;
            ll c1=upper_bound(A.begin()+xbeg+xlo,A.begin()+xbeg+xhi,q)-A.begin()-xbeg;
            q[0]=Y;
            ll c2=upper_bound(A.begin()+ybeg+ylo,A.begin()+ybeg+yhi,q)-A.begin()-ybeg;
            if(c1+c2<=xc){
                lo=mid;
                xlo=c1;
                ylo=c2;
                ans=c2;
            }
            else{
                hi=mid;
                xhi=c1;
                yhi=c2;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}

SubtaskSumTestVerdictTimeMemory
base29/45
1Accepted0/01ms316 KiB
2Accepted0/02ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/23ms316 KiB
8Accepted2/23ms500 KiB
9Accepted3/32ms316 KiB
10Wrong answer0/2166ms2036 KiB
11Wrong answer0/2166ms2080 KiB
12Wrong answer0/2172ms2000 KiB
13Wrong answer0/2170ms2028 KiB
14Wrong answer0/3187ms2100 KiB
15Wrong answer0/3184ms2036 KiB
16Accepted2/2188ms2004 KiB
17Wrong answer0/2209ms2004 KiB
18Accepted2/2204ms2100 KiB
19Accepted2/2119ms1216 KiB
20Accepted2/2218ms2516 KiB
21Accepted2/2199ms2356 KiB
22Accepted2/2209ms2356 KiB
23Accepted2/2200ms2320 KiB