/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 213ms 672.0 KiB
#3 Accepted 218ms 912.0 KiB
#4 Accepted 220ms 932.0 KiB
#5 Accepted 258ms 2.324 MiB
#6 Accepted 254ms 2.297 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-10-03 13:26:00
Judged By
Score
100
Total Time
258ms
Peak Memory
2.324 MiB