#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
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 =
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
340 KB |
Output is correct |
3 |
Correct |
29 ms |
340 KB |
Output is correct |
4 |
Correct |
32 ms |
340 KB |
Output is correct |
5 |
Correct |
27 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
17 ms |
400 KB |
Output is correct |
8 |
Correct |
19 ms |
340 KB |
Output is correct |
9 |
Correct |
22 ms |
340 KB |
Output is correct |
10 |
Correct |
18 ms |
316 KB |
Output is correct |
11 |
Correct |
18 ms |
340 KB |
Output is correct |
12 |
Correct |
19 ms |
424 KB |
Output is correct |
13 |
Correct |
17 ms |
444 KB |
Output is correct |
14 |
Correct |
18 ms |
416 KB |
Output is correct |
15 |
Correct |
17 ms |
340 KB |
Output is correct |
16 |
Correct |
16 ms |
416 KB |
Output is correct |
17 |
Correct |
16 ms |
416 KB |
Output is correct |
18 |
Correct |
15 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
340 KB |
Output is correct |
3 |
Correct |
29 ms |
340 KB |
Output is correct |
4 |
Correct |
32 ms |
340 KB |
Output is correct |
5 |
Correct |
27 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
17 ms |
400 KB |
Output is correct |
8 |
Correct |
19 ms |
340 KB |
Output is correct |
9 |
Correct |
22 ms |
340 KB |
Output is correct |
10 |
Correct |
18 ms |
316 KB |
Output is correct |
11 |
Correct |
18 ms |
340 KB |
Output is correct |
12 |
Correct |
19 ms |
424 KB |
Output is correct |
13 |
Correct |
17 ms |
444 KB |
Output is correct |
14 |
Correct |
18 ms |
416 KB |
Output is correct |
15 |
Correct |
17 ms |
340 KB |
Output is correct |
16 |
Correct |
16 ms |
416 KB |
Output is correct |
17 |
Correct |
16 ms |
416 KB |
Output is correct |
18 |
Correct |
15 ms |
340 KB |
Output is correct |
19 |
Correct |
354 ms |
740 KB |
Output is correct |
20 |
Correct |
469 ms |
800 KB |
Output is correct |
21 |
Correct |
256 ms |
788 KB |
Output is correct |
22 |
Correct |
340 ms |
792 KB |
Output is correct |
23 |
Correct |
278 ms |
760 KB |
Output is correct |
24 |
Correct |
262 ms |
780 KB |
Output is correct |
25 |
Correct |
247 ms |
752 KB |
Output is correct |
26 |
Correct |
269 ms |
764 KB |
Output is correct |
27 |
Correct |
225 ms |
744 KB |
Output is correct |
28 |
Correct |
257 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1459 ms |
852 KB |
Output is correct |
2 |
Correct |
8404 ms |
1748 KB |
Output is correct |
3 |
Execution timed out |
9068 ms |
2640 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
340 KB |
Output is correct |
3 |
Correct |
29 ms |
340 KB |
Output is correct |
4 |
Correct |
32 ms |
340 KB |
Output is correct |
5 |
Correct |
27 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
17 ms |
400 KB |
Output is correct |
8 |
Correct |
19 ms |
340 KB |
Output is correct |
9 |
Correct |
22 ms |
340 KB |
Output is correct |
10 |
Correct |
18 ms |
316 KB |
Output is correct |
11 |
Correct |
18 ms |
340 KB |
Output is correct |
12 |
Correct |
19 ms |
424 KB |
Output is correct |
13 |
Correct |
17 ms |
444 KB |
Output is correct |
14 |
Correct |
18 ms |
416 KB |
Output is correct |
15 |
Correct |
17 ms |
340 KB |
Output is correct |
16 |
Correct |
16 ms |
416 KB |
Output is correct |
17 |
Correct |
16 ms |
416 KB |
Output is correct |
18 |
Correct |
15 ms |
340 KB |
Output is correct |
19 |
Correct |
354 ms |
740 KB |
Output is correct |
20 |
Correct |
469 ms |
800 KB |
Output is correct |
21 |
Correct |
256 ms |
788 KB |
Output is correct |
22 |
Correct |
340 ms |
792 KB |
Output is correct |
23 |
Correct |
278 ms |
760 KB |
Output is correct |
24 |
Correct |
262 ms |
780 KB |
Output is correct |
25 |
Correct |
247 ms |
752 KB |
Output is correct |
26 |
Correct |
269 ms |
764 KB |
Output is correct |
27 |
Correct |
225 ms |
744 KB |
Output is correct |
28 |
Correct |
257 ms |
748 KB |
Output is correct |
29 |
Correct |
1459 ms |
852 KB |
Output is correct |
30 |
Correct |
8404 ms |
1748 KB |
Output is correct |
31 |
Execution timed out |
9068 ms |
2640 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |