#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 < n; k++) f[j] += (a[j] >= a[k]);
for(int i = 0; i < pos.size(); i++) {
int idx = pos[i];
for(int j = 0; j < n; j++) f[j] -= (a[j] >= a[idx]);
a[idx] = val[i];
for(int j = 0; j < n; j++) f[j] += (a[j] >= a[idx]);
f[idx] = 0;
for(int j = 0; j < n; j++) f[idx] += (a[idx] >= a[j]);
for(int j = 0; j < n; j++) ans[i] = max(ans[i], j + 1 - 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++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
17 ms |
284 KB |
Output is correct |
4 |
Correct |
18 ms |
356 KB |
Output is correct |
5 |
Correct |
18 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
18 ms |
360 KB |
Output is correct |
8 |
Correct |
18 ms |
340 KB |
Output is correct |
9 |
Correct |
17 ms |
340 KB |
Output is correct |
10 |
Correct |
17 ms |
364 KB |
Output is correct |
11 |
Correct |
17 ms |
340 KB |
Output is correct |
12 |
Correct |
18 ms |
368 KB |
Output is correct |
13 |
Correct |
18 ms |
360 KB |
Output is correct |
14 |
Correct |
19 ms |
364 KB |
Output is correct |
15 |
Correct |
19 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
340 KB |
Output is correct |
17 |
Correct |
19 ms |
340 KB |
Output is correct |
18 |
Correct |
18 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
17 ms |
284 KB |
Output is correct |
4 |
Correct |
18 ms |
356 KB |
Output is correct |
5 |
Correct |
18 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
18 ms |
360 KB |
Output is correct |
8 |
Correct |
18 ms |
340 KB |
Output is correct |
9 |
Correct |
17 ms |
340 KB |
Output is correct |
10 |
Correct |
17 ms |
364 KB |
Output is correct |
11 |
Correct |
17 ms |
340 KB |
Output is correct |
12 |
Correct |
18 ms |
368 KB |
Output is correct |
13 |
Correct |
18 ms |
360 KB |
Output is correct |
14 |
Correct |
19 ms |
364 KB |
Output is correct |
15 |
Correct |
19 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
340 KB |
Output is correct |
17 |
Correct |
19 ms |
340 KB |
Output is correct |
18 |
Correct |
18 ms |
360 KB |
Output is correct |
19 |
Correct |
222 ms |
616 KB |
Output is correct |
20 |
Correct |
265 ms |
652 KB |
Output is correct |
21 |
Correct |
263 ms |
656 KB |
Output is correct |
22 |
Correct |
263 ms |
536 KB |
Output is correct |
23 |
Correct |
265 ms |
648 KB |
Output is correct |
24 |
Correct |
261 ms |
536 KB |
Output is correct |
25 |
Correct |
255 ms |
656 KB |
Output is correct |
26 |
Correct |
274 ms |
524 KB |
Output is correct |
27 |
Correct |
260 ms |
540 KB |
Output is correct |
28 |
Correct |
267 ms |
536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
824 ms |
560 KB |
Output is correct |
2 |
Correct |
4474 ms |
1328 KB |
Output is correct |
3 |
Execution timed out |
9090 ms |
1884 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
17 ms |
284 KB |
Output is correct |
4 |
Correct |
18 ms |
356 KB |
Output is correct |
5 |
Correct |
18 ms |
340 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
18 ms |
360 KB |
Output is correct |
8 |
Correct |
18 ms |
340 KB |
Output is correct |
9 |
Correct |
17 ms |
340 KB |
Output is correct |
10 |
Correct |
17 ms |
364 KB |
Output is correct |
11 |
Correct |
17 ms |
340 KB |
Output is correct |
12 |
Correct |
18 ms |
368 KB |
Output is correct |
13 |
Correct |
18 ms |
360 KB |
Output is correct |
14 |
Correct |
19 ms |
364 KB |
Output is correct |
15 |
Correct |
19 ms |
340 KB |
Output is correct |
16 |
Correct |
18 ms |
340 KB |
Output is correct |
17 |
Correct |
19 ms |
340 KB |
Output is correct |
18 |
Correct |
18 ms |
360 KB |
Output is correct |
19 |
Correct |
222 ms |
616 KB |
Output is correct |
20 |
Correct |
265 ms |
652 KB |
Output is correct |
21 |
Correct |
263 ms |
656 KB |
Output is correct |
22 |
Correct |
263 ms |
536 KB |
Output is correct |
23 |
Correct |
265 ms |
648 KB |
Output is correct |
24 |
Correct |
261 ms |
536 KB |
Output is correct |
25 |
Correct |
255 ms |
656 KB |
Output is correct |
26 |
Correct |
274 ms |
524 KB |
Output is correct |
27 |
Correct |
260 ms |
540 KB |
Output is correct |
28 |
Correct |
267 ms |
536 KB |
Output is correct |
29 |
Correct |
824 ms |
560 KB |
Output is correct |
30 |
Correct |
4474 ms |
1328 KB |
Output is correct |
31 |
Execution timed out |
9090 ms |
1884 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |