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>
constexpr int inf = 1 << 30;
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V) {
const int N = (int)A.size(), Q = (int)X.size();
{
std::vector<int> vals;
std::copy(A.begin(), A.end(), std::back_inserter(vals));
std::copy(V.begin(), V.end(), std::back_inserter(vals));
std::sort(vals.begin(), vals.end());
for (auto &e : A) e = (int)(std::lower_bound(vals.begin(), vals.end(), e) - vals.begin());
for (auto &e : V) e = (int)(std::lower_bound(vals.begin(), vals.end(), e) - vals.begin());
}
// subtask 1, 2
const int M =
std::max(*std::max_element(A.begin(), A.end()), *std::max_element(V.begin(), V.end())) + 1;
std::vector<int> countL(N);
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
if (A[i] > A[j]) {
++countL[j];
}
}
}
std::vector<int> answer(Q);
for (int q = 0; q < Q; ++q) {
const int x = X[q], newVal = V[q];
const int preVal = A[x];
for (int i = x + 1; i < N; ++i) {
if (preVal > A[i]) {
--countL[i];
}
}
A[x] = newVal;
for (int i = x + 1; i < N; ++i) {
if (newVal > A[i]) {
++countL[i];
}
}
countL[x] = 0;
for (int i = 0; i < x; ++i) {
if (A[i] > newVal) {
++countL[x];
}
}
answer[q] = *std::max_element(countL.begin(), countL.end());
}
return answer;
}
Compilation message (stderr)
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:17:15: warning: unused variable 'M' [-Wunused-variable]
17 | const int M =
| ^
# | 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... |