/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 207ms 596.0 KiB
#3 Accepted 217ms 860.0 KiB
#4 Accepted 211ms 916.0 KiB
#5 Accepted 251ms 2.301 MiB
#6 Accepted 262ms 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-11-11 03:13:56
Judged By
Score
100
Total Time
262ms
Peak Memory
2.352 MiB