/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 190ms 652.0 KiB
#3 Accepted 191ms 784.0 KiB
#4 Accepted 198ms 828.0 KiB
#5 Accepted 230ms 2.359 MiB
#6 Accepted 261ms 2.352 MiB

Code


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

// Pair of (value, index)
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;

    vector<int> a(n);
    priority_queue<pii, vector<pii>, greater<pii>> minHeap;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        minHeap.push({a[i], i});
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;

        // Get the minimum element
        while (minHeap.top().first != a[minHeap.top().second]) {
            minHeap.pop();
        }

        pii minElement = minHeap.top();
        minHeap.pop();

        // Output the position (1-based index)
        cout << minElement.second + 1 << endl;

        // Replace the minimum element in the array with x
        a[minElement.second] = x;

        // Insert the new value back into the heap
        minHeap.push({x, minElement.second});
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1086 KuZ the Position
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:46:50
Judged At
2024-08-16 16:46:50
Judged By
Score
100
Total Time
261ms
Peak Memory
2.359 MiB