/ SeriousOJ /

Record Detail

Compile Error

foo.cc:52:5: error: redefinition of 'int main()'
   52 | int main() {
      |     ^~~~
foo.cc:7:5: note: 'int main()' previously defined here
    7 | int main() {
      |     ^~~~

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;
}
#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:23
Judged At
2024-10-03 13:26:03
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes