Submission #1301330

#TimeUsernameProblemLanguageResultExecution timeMemory
1301330mduchelloBubble Sort 2 (JOI18_bubblesort2)C++20
17 / 100
9091 ms5748 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
    int n = A.size();
    int Q = X.size();
    vector<int> res(Q);

    for(int k = 0; k < Q; k++){
        // update A
        A[X[k]] = V[k];

        // copy và sort để tìm vị trí đúng
        vector<int> sortedA = A;
        sort(sortedA.begin(), sortedA.end());

        // map value -> queue các vị trí trong sorted array
        unordered_map<int, queue<int>> mp;
        for(int i = 0; i < n; i++){
            mp[sortedA[i]].push(i);
        }

        int pass_count = 0;
        for(int i = 0; i < n; i++){
            int correct_pos = mp[A[i]].front();
            mp[A[i]].pop();
            if(i > correct_pos){
                pass_count = max(pass_count, i - correct_pos);
            }
        }

        res[k] = pass_count;
    }

    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...