#include <bits/stdc++.h>
template <class T>
using Vec = std::vector<T>;
Vec<int> countScans(Vec<int> A, Vec<int> X, Vec<int> V) {
const int N = A.size();
const int Q = X.size();
Vec<int> big(N);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < i; ++j) {
if (A[j] > A[i]) {
big[i] += 1;
}
}
}
Vec<int> ret(Q);
for (int i = 0; i < Q; ++i) {
for (int j = X[i] + 1; j < N; ++j) {
if (A[X[i]] <= A[j] && V[i] > A[j]) {
big[j] += 1;
}
if (A[X[i]] > A[j] && V[i] <= A[j]) {
big[j] -= 1;
}
}
A[X[i]] = V[i];
big[X[i]] = 0;
for (int j = 0; j < X[i]; ++j) {
if (A[j] > A[X[i]]) {
big[X[i]] += 1;
}
}
ret[i] = *std::max_element(big.begin(), big.end());
}
return ret;
}
#ifdef __APPLE__
int main() {
int N, Q;
std::cin >> N >> Q;
Vec<int> A(N);
Vec<int> X(Q), V(Q);
for (auto &x: A) {
std::cin >> x;
}
for (int i = 0; i < Q; ++i) {
std::cin >> X[i] >> V[i];
}
for (auto x: countScans(A, X, V)) {
std::cout << x << '\n';
}
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
33 ms |
492 KB |
Output is correct |
4 |
Correct |
30 ms |
492 KB |
Output is correct |
5 |
Correct |
25 ms |
492 KB |
Output is correct |
6 |
Correct |
18 ms |
492 KB |
Output is correct |
7 |
Correct |
21 ms |
492 KB |
Output is correct |
8 |
Correct |
26 ms |
492 KB |
Output is correct |
9 |
Correct |
27 ms |
492 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
21 ms |
492 KB |
Output is correct |
12 |
Correct |
22 ms |
492 KB |
Output is correct |
13 |
Correct |
23 ms |
492 KB |
Output is correct |
14 |
Correct |
22 ms |
488 KB |
Output is correct |
15 |
Correct |
22 ms |
492 KB |
Output is correct |
16 |
Correct |
19 ms |
492 KB |
Output is correct |
17 |
Correct |
18 ms |
492 KB |
Output is correct |
18 |
Correct |
18 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
33 ms |
492 KB |
Output is correct |
4 |
Correct |
30 ms |
492 KB |
Output is correct |
5 |
Correct |
25 ms |
492 KB |
Output is correct |
6 |
Correct |
18 ms |
492 KB |
Output is correct |
7 |
Correct |
21 ms |
492 KB |
Output is correct |
8 |
Correct |
26 ms |
492 KB |
Output is correct |
9 |
Correct |
27 ms |
492 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
21 ms |
492 KB |
Output is correct |
12 |
Correct |
22 ms |
492 KB |
Output is correct |
13 |
Correct |
23 ms |
492 KB |
Output is correct |
14 |
Correct |
22 ms |
488 KB |
Output is correct |
15 |
Correct |
22 ms |
492 KB |
Output is correct |
16 |
Correct |
19 ms |
492 KB |
Output is correct |
17 |
Correct |
18 ms |
492 KB |
Output is correct |
18 |
Correct |
18 ms |
492 KB |
Output is correct |
19 |
Correct |
391 ms |
732 KB |
Output is correct |
20 |
Correct |
505 ms |
748 KB |
Output is correct |
21 |
Correct |
323 ms |
788 KB |
Output is correct |
22 |
Correct |
392 ms |
816 KB |
Output is correct |
23 |
Correct |
323 ms |
748 KB |
Output is correct |
24 |
Correct |
314 ms |
756 KB |
Output is correct |
25 |
Correct |
304 ms |
748 KB |
Output is correct |
26 |
Correct |
316 ms |
748 KB |
Output is correct |
27 |
Correct |
298 ms |
748 KB |
Output is correct |
28 |
Correct |
297 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1765 ms |
824 KB |
Output is correct |
2 |
Execution timed out |
9025 ms |
1556 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Correct |
6 ms |
364 KB |
Output is correct |
3 |
Correct |
33 ms |
492 KB |
Output is correct |
4 |
Correct |
30 ms |
492 KB |
Output is correct |
5 |
Correct |
25 ms |
492 KB |
Output is correct |
6 |
Correct |
18 ms |
492 KB |
Output is correct |
7 |
Correct |
21 ms |
492 KB |
Output is correct |
8 |
Correct |
26 ms |
492 KB |
Output is correct |
9 |
Correct |
27 ms |
492 KB |
Output is correct |
10 |
Correct |
21 ms |
492 KB |
Output is correct |
11 |
Correct |
21 ms |
492 KB |
Output is correct |
12 |
Correct |
22 ms |
492 KB |
Output is correct |
13 |
Correct |
23 ms |
492 KB |
Output is correct |
14 |
Correct |
22 ms |
488 KB |
Output is correct |
15 |
Correct |
22 ms |
492 KB |
Output is correct |
16 |
Correct |
19 ms |
492 KB |
Output is correct |
17 |
Correct |
18 ms |
492 KB |
Output is correct |
18 |
Correct |
18 ms |
492 KB |
Output is correct |
19 |
Correct |
391 ms |
732 KB |
Output is correct |
20 |
Correct |
505 ms |
748 KB |
Output is correct |
21 |
Correct |
323 ms |
788 KB |
Output is correct |
22 |
Correct |
392 ms |
816 KB |
Output is correct |
23 |
Correct |
323 ms |
748 KB |
Output is correct |
24 |
Correct |
314 ms |
756 KB |
Output is correct |
25 |
Correct |
304 ms |
748 KB |
Output is correct |
26 |
Correct |
316 ms |
748 KB |
Output is correct |
27 |
Correct |
298 ms |
748 KB |
Output is correct |
28 |
Correct |
297 ms |
768 KB |
Output is correct |
29 |
Correct |
1765 ms |
824 KB |
Output is correct |
30 |
Execution timed out |
9025 ms |
1556 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |