#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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |