This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
std::vector<int> countScans(vector<int> a, vector<int> X, vector<int> V){
int n = a.size();
int q = X.size();
vector<int> ans(q);
vector<int> cnt(n, 0);
for(int i = 0; i < n; ++i) {
for(int j = 0; j < i; ++j) {
if(a[j] > a[i]) ++cnt[i];
}
}
for(int k = 0; k < q; ++k) {
int i = X[k];
for(int j = i + 1; j < n; ++j) {
if(a[i] > a[j]) --cnt[j];
}
a[i] = V[k];
for(int j = i + 1; j < n; ++j) {
if(a[i] > a[j]) ++cnt[j];
}
cnt[i] = 0;
for(int j = 0; j < i; ++j) {
if(a[j] > a[i]) ++cnt[i];
}
int mx = *max_element(cnt.begin(), cnt.end());
ans[k] = mx;
}
return ans;
}
/*
4 2
1 2 3 4
0 3
2 1
*/
# | 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... |