#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 01;
int f[N];
vector<int> countScans(vector<int> a, vector<int> pos, vector<int> val) {
vector<int> ans(pos.size());
int n = a.size();
for(int j = 0; j < n; j++) for(int k = 0; k < j; k++) f[j] += (a[j] < a[k]);
for(int i = 0; i < pos.size(); i++) {
int idx = pos[i];
for(int j = idx + 1; j < n; j++) f[j] -= (a[j] < a[idx]);
a[idx] = val[i];
for(int j = idx + 1; j < n; j++) f[j] += (a[j] < a[idx]);
f[idx] = 0;
for(int j = 0; j < idx; j++) f[idx] += (a[idx] < a[j]);
for(int j = 0; j < n; j++) ans[i] = max(ans[i], f[j]);
}
return ans;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n, q; cin >> n >> q;
vector<int> a(n), x(q), v(q);
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0; i < q; i++) cin >> x[i] >> v[i];
vector<int> ret = countScans(a, x, v);
for(int &j : ret) cout << j << endl;
}
#endif // ngu
Compilation message
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 0; i < pos.size(); i++) {
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
368 KB |
Output is correct |
4 |
Correct |
12 ms |
412 KB |
Output is correct |
5 |
Correct |
12 ms |
424 KB |
Output is correct |
6 |
Correct |
12 ms |
324 KB |
Output is correct |
7 |
Correct |
12 ms |
416 KB |
Output is correct |
8 |
Correct |
12 ms |
320 KB |
Output is correct |
9 |
Correct |
13 ms |
416 KB |
Output is correct |
10 |
Correct |
12 ms |
320 KB |
Output is correct |
11 |
Correct |
14 ms |
324 KB |
Output is correct |
12 |
Correct |
11 ms |
412 KB |
Output is correct |
13 |
Correct |
13 ms |
352 KB |
Output is correct |
14 |
Correct |
11 ms |
340 KB |
Output is correct |
15 |
Correct |
11 ms |
340 KB |
Output is correct |
16 |
Correct |
11 ms |
400 KB |
Output is correct |
17 |
Correct |
11 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
368 KB |
Output is correct |
4 |
Correct |
12 ms |
412 KB |
Output is correct |
5 |
Correct |
12 ms |
424 KB |
Output is correct |
6 |
Correct |
12 ms |
324 KB |
Output is correct |
7 |
Correct |
12 ms |
416 KB |
Output is correct |
8 |
Correct |
12 ms |
320 KB |
Output is correct |
9 |
Correct |
13 ms |
416 KB |
Output is correct |
10 |
Correct |
12 ms |
320 KB |
Output is correct |
11 |
Correct |
14 ms |
324 KB |
Output is correct |
12 |
Correct |
11 ms |
412 KB |
Output is correct |
13 |
Correct |
13 ms |
352 KB |
Output is correct |
14 |
Correct |
11 ms |
340 KB |
Output is correct |
15 |
Correct |
11 ms |
340 KB |
Output is correct |
16 |
Correct |
11 ms |
400 KB |
Output is correct |
17 |
Correct |
11 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
412 KB |
Output is correct |
19 |
Correct |
153 ms |
672 KB |
Output is correct |
20 |
Correct |
178 ms |
728 KB |
Output is correct |
21 |
Correct |
178 ms |
740 KB |
Output is correct |
22 |
Correct |
191 ms |
736 KB |
Output is correct |
23 |
Correct |
176 ms |
712 KB |
Output is correct |
24 |
Correct |
176 ms |
700 KB |
Output is correct |
25 |
Correct |
175 ms |
692 KB |
Output is correct |
26 |
Correct |
180 ms |
700 KB |
Output is correct |
27 |
Correct |
162 ms |
692 KB |
Output is correct |
28 |
Correct |
165 ms |
692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
478 ms |
644 KB |
Output is correct |
2 |
Correct |
2814 ms |
1568 KB |
Output is correct |
3 |
Correct |
6223 ms |
2632 KB |
Output is correct |
4 |
Correct |
6286 ms |
2436 KB |
Output is correct |
5 |
Correct |
6322 ms |
2404 KB |
Output is correct |
6 |
Correct |
6363 ms |
2796 KB |
Output is correct |
7 |
Correct |
6287 ms |
2516 KB |
Output is correct |
8 |
Correct |
6302 ms |
2532 KB |
Output is correct |
9 |
Correct |
6260 ms |
2476 KB |
Output is correct |
10 |
Correct |
5894 ms |
2524 KB |
Output is correct |
11 |
Correct |
5816 ms |
2720 KB |
Output is correct |
12 |
Correct |
5941 ms |
2524 KB |
Output is correct |
13 |
Correct |
5609 ms |
2792 KB |
Output is correct |
14 |
Correct |
5592 ms |
2564 KB |
Output is correct |
15 |
Correct |
5593 ms |
2620 KB |
Output is correct |
16 |
Correct |
5426 ms |
2500 KB |
Output is correct |
17 |
Correct |
5376 ms |
2612 KB |
Output is correct |
18 |
Correct |
5364 ms |
2700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
212 KB |
Output is correct |
3 |
Correct |
23 ms |
368 KB |
Output is correct |
4 |
Correct |
12 ms |
412 KB |
Output is correct |
5 |
Correct |
12 ms |
424 KB |
Output is correct |
6 |
Correct |
12 ms |
324 KB |
Output is correct |
7 |
Correct |
12 ms |
416 KB |
Output is correct |
8 |
Correct |
12 ms |
320 KB |
Output is correct |
9 |
Correct |
13 ms |
416 KB |
Output is correct |
10 |
Correct |
12 ms |
320 KB |
Output is correct |
11 |
Correct |
14 ms |
324 KB |
Output is correct |
12 |
Correct |
11 ms |
412 KB |
Output is correct |
13 |
Correct |
13 ms |
352 KB |
Output is correct |
14 |
Correct |
11 ms |
340 KB |
Output is correct |
15 |
Correct |
11 ms |
340 KB |
Output is correct |
16 |
Correct |
11 ms |
400 KB |
Output is correct |
17 |
Correct |
11 ms |
340 KB |
Output is correct |
18 |
Correct |
12 ms |
412 KB |
Output is correct |
19 |
Correct |
153 ms |
672 KB |
Output is correct |
20 |
Correct |
178 ms |
728 KB |
Output is correct |
21 |
Correct |
178 ms |
740 KB |
Output is correct |
22 |
Correct |
191 ms |
736 KB |
Output is correct |
23 |
Correct |
176 ms |
712 KB |
Output is correct |
24 |
Correct |
176 ms |
700 KB |
Output is correct |
25 |
Correct |
175 ms |
692 KB |
Output is correct |
26 |
Correct |
180 ms |
700 KB |
Output is correct |
27 |
Correct |
162 ms |
692 KB |
Output is correct |
28 |
Correct |
165 ms |
692 KB |
Output is correct |
29 |
Correct |
478 ms |
644 KB |
Output is correct |
30 |
Correct |
2814 ms |
1568 KB |
Output is correct |
31 |
Correct |
6223 ms |
2632 KB |
Output is correct |
32 |
Correct |
6286 ms |
2436 KB |
Output is correct |
33 |
Correct |
6322 ms |
2404 KB |
Output is correct |
34 |
Correct |
6363 ms |
2796 KB |
Output is correct |
35 |
Correct |
6287 ms |
2516 KB |
Output is correct |
36 |
Correct |
6302 ms |
2532 KB |
Output is correct |
37 |
Correct |
6260 ms |
2476 KB |
Output is correct |
38 |
Correct |
5894 ms |
2524 KB |
Output is correct |
39 |
Correct |
5816 ms |
2720 KB |
Output is correct |
40 |
Correct |
5941 ms |
2524 KB |
Output is correct |
41 |
Correct |
5609 ms |
2792 KB |
Output is correct |
42 |
Correct |
5592 ms |
2564 KB |
Output is correct |
43 |
Correct |
5593 ms |
2620 KB |
Output is correct |
44 |
Correct |
5426 ms |
2500 KB |
Output is correct |
45 |
Correct |
5376 ms |
2612 KB |
Output is correct |
46 |
Correct |
5364 ms |
2700 KB |
Output is correct |
47 |
Runtime error |
4276 ms |
12828 KB |
Execution killed with signal 11 |
48 |
Halted |
0 ms |
0 KB |
- |