Submission #1301322

#TimeUsernameProblemLanguageResultExecution timeMemory
1301322mduchelloBubble Sort 2 (JOI18_bubblesort2)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

#define nmax 100007

int n, q;
int a[nmax];
int b2[nmax];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> q;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int k = 1; k <= q; k++) {
        int pos, val;
        cin >> pos >> val;
        pos++; // nếu input 0-based, nếu 1-based thì bỏ dòng này

        a[pos] = val; // update giá trị tại vị trí pos

        // tính số pass Bubble Sort sau update
        for(int i = 1; i <= n; i++) b2[i] = a[i];
        sort(b2 + 1, b2 + n + 1);

        vector<queue<int>> mp(8007); // giả sử giá trị a[i] <= 8000
        for(int i = 1; i <= n; i++) mp[b2[i]].push(i);

        int pass = 0;
        for(int i = 1; i <= n; i++) {
            int correct_pos = mp[a[i]].front();
            mp[a[i]].pop();
            if(i > correct_pos) pass = max(pass, i - correct_pos);
        }
        cout << pass << '\n'; // in kết quả ngay lập tức
    }

    return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccX00bY7.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cchFN45h.o:bubblesort2.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccX00bY7.o: in function `main':
grader.cpp:(.text.startup+0x189): undefined reference to `countScans(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status