/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 56ms 4.258 MiB
#3 Accepted 56ms 4.449 MiB
#4 Accepted 56ms 4.254 MiB
#5 Accepted 56ms 4.258 MiB
#6 Accepted 56ms 4.25 MiB
#7 Accepted 53ms 4.234 MiB
#8 Accepted 48ms 4.328 MiB
#9 Accepted 47ms 4.156 MiB
#10 Accepted 44ms 4.246 MiB
#11 Accepted 34ms 3.383 MiB
#12 Accepted 10ms 1.395 MiB

Code

#include<bits/stdc++.h>
using namespace std;

#define RASHED ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long int

#define show(x) cout << #x << " = " << x << endl
#define inf (int)1e17
#define maxn 100010

#define F first
#define S second

void solve(int tc) {
    int n;
    cin>>n;
    vector<int> onsite;
    for(int i=1; i<=n; i++) {
        int x;
        cin>>x;
        onsite.push_back(x);
    }
    sort(onsite.rbegin(),onsite.rend());
    int m;
    cin>>m;
    vector<pair<int,int>> replay;
    int res[m+8],N = n+1;
    for(int i=1; i<=m; i++) {
        int x;
        cin>>x;
        replay.push_back({x,-i});
    }
    sort(replay.rbegin(),replay.rend());
    for(int i=0; i<m; i++) {
        int val = replay[i].F,pos = -(replay[i].S);
        int lo = 0,hi = n-1,pp = inf;
        while(lo <= hi) {
            int mid = (lo+hi)/2;
            if(val > onsite[mid]) {
                pp = min(pp,mid+1);
                hi = mid-1;
            } else lo = mid+1;
        }
        ///show(pp);
        if(pp == inf) res[pos] = n+i+1;
        else res[pos] = pp+i;
    }
    for(int i=1; i<m; i++)cout<<res[i]<<" ";
    cout<<res[m];
}
signed main() {
    RASHED
    int TC = 1;
    ///cin>>TC;
    for(int i=1; i<=TC; i++)solve(i);
    return 0;
}
/**
CASES:

*/

Information

Submit By
Type
Submission
Problem
P1049 Combined scoreboard
Language
C++20 (G++ 13.2.0)
Submit At
2024-05-07 13:32:51
Judged At
2024-11-11 03:30:53
Judged By
Score
100
Total Time
56ms
Peak Memory
4.449 MiB