/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 98ms 9.559 MiB
#3 Accepted 100ms 9.527 MiB
#4 Accepted 99ms 9.547 MiB
#5 Accepted 99ms 9.461 MiB
#6 Accepted 99ms 9.574 MiB
#7 Accepted 98ms 9.504 MiB
#8 Accepted 95ms 9.566 MiB
#9 Accepted 93ms 9.465 MiB
#10 Accepted 89ms 9.5 MiB
#11 Accepted 58ms 5.266 MiB
#12 Accepted 18ms 1.891 MiB

Code

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

bool compare(const tuple<int, int, int>& a, const tuple<int, int, int>& b) {
    if (get<0>(a) != get<0>(b)) // Compare first elements
        return get<0>(a) > get<0>(b); // If not equal, return comparison result
    
    if (get<1>(a) != get<1>(b)) // If first elements are equal, compare second elements
        return get<1>(a) < get<1>(b); // If not equal, return comparison result
    
    return get<2>(a) < get<2>(b); // If both first and second elements are equal, compare third elements
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long t;
    //cin >> t;
    t = 1;
    while (t--) {
        long long n;
        cin >> n;
        long long a[n];
        for (long long i = 0; i < n; i++) {
            cin >> a[i];
        }
        long long m;
        cin >> m;
        long long b[m];
        for (long long i = 0; i < m; i++) {
            cin >> b[i];
        }

        vector<tuple<long long, long long, long long>> v;
        for (long long i = 0; i < n; i++) {
            v.push_back({a[i], 1, i});
        }
        for (long long i = 0; i < m; i++) {
            v.push_back({b[i], 2, i});
        }
        
        sort(v.begin(), v.end(), compare);
        
        long long p[m];
        for (long long i = 0; i < m + n; i++) {
            if (get<1>(v[i]) == 2)
                p[get<2>(v[i])] = i;
        }
        
        for (long long i = 0; i < m; i++) {
            cout << p[i]+1 << " ";
        }
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1049 Combined scoreboard
Contest
Brain Booster #3
Language
C++11 (G++ 13.2.0)
Submit At
2024-05-06 15:41:22
Judged At
2024-11-11 03:34:01
Judged By
Score
100
Total Time
100ms
Peak Memory
9.574 MiB