/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 34ms 4.281 MiB
#3 Accepted 34ms 4.293 MiB
#4 Accepted 34ms 4.293 MiB
#5 Accepted 34ms 4.25 MiB
#6 Accepted 34ms 4.242 MiB
#7 Accepted 32ms 4.242 MiB
#8 Accepted 30ms 4.246 MiB
#9 Accepted 30ms 4.254 MiB
#10 Accepted 26ms 4.238 MiB
#11 Accepted 22ms 3.555 MiB
#12 Accepted 7ms 1.355 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-05-07 13:32:51
Judged By
Score
100
Total Time
34ms
Peak Memory
4.293 MiB