#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 50;
const int INF = 1 << 25;
int mx[4 * N], delta[4 * N];
vector<pair<int, int>> D;
void add(int v, int l, int r, int L, int R, int d) {
if (R <= L || R <= l || r <= L) return;
if (l >= L && r <= R) {
mx[v] += d;
delta[v] += d;
return;
}
int m = l + r >> 1;
add(v<<1, l, m, L, R, d);
add(v<<1|1, m, r, L, R, d);
mx[v] = max(mx[v<<1], mx[v<<1|1]) + delta[v];
}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
int Q = X.size();
int n = A.size();
for (int i = 0; i < n; i++)
D.emplace_back(A[i], i);
for (int i = 0; i < Q; i++)
D.emplace_back(V[i], X[i]);
sort(D.begin(), D.end());
D.resize(unique(D.begin(), D.end()) - D.begin());
for (int i = 0; i < A.size(); i++) {
int ind = lower_bound(D.begin(), D.end(), make_pair(A[i], i)) - D.begin();
add(1, 0, D.size(), ind, ind + 1, +i);
add(1, 0, D.size(), ind + 1, D.size(), -1);
}
vector<int> answer(Q);
for (int i = 0; i < Q; i++) {
int ind = lower_bound(D.begin(), D.end(), make_pair(A[X[i]], X[i])) - D.begin();
add(1, 0, D.size(), ind, ind + 1, -X[i]);
add(1, 0, D.size(), ind + 1, D.size(), +1);
ind = lower_bound(D.begin(), D.end(), make_pair(V[i], X[i])) - D.begin();
add(1, 0, D.size(), ind, ind + 1, +X[i]);
add(1, 0, D.size(), ind + 1, D.size(), -1);
A[X[i]] = V[i];
answer[i] = max(mx[1], 0);
}
return answer;
}
Compilation message
bubblesort2.cpp: In function 'void add(int, int, int, int, int, int)':
bubblesort2.cpp:17:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
17 | int m = l + r >> 1;
| ~~^~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 0; i < A.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
388 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
488 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
388 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
488 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
12 ms |
980 KB |
Output is correct |
20 |
Correct |
15 ms |
1016 KB |
Output is correct |
21 |
Correct |
14 ms |
1116 KB |
Output is correct |
22 |
Correct |
14 ms |
1024 KB |
Output is correct |
23 |
Correct |
15 ms |
984 KB |
Output is correct |
24 |
Correct |
13 ms |
980 KB |
Output is correct |
25 |
Correct |
13 ms |
1024 KB |
Output is correct |
26 |
Correct |
13 ms |
980 KB |
Output is correct |
27 |
Correct |
13 ms |
1028 KB |
Output is correct |
28 |
Correct |
18 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1360 KB |
Output is correct |
2 |
Correct |
60 ms |
2636 KB |
Output is correct |
3 |
Correct |
102 ms |
4492 KB |
Output is correct |
4 |
Correct |
106 ms |
4520 KB |
Output is correct |
5 |
Correct |
100 ms |
4524 KB |
Output is correct |
6 |
Correct |
106 ms |
4460 KB |
Output is correct |
7 |
Correct |
102 ms |
4416 KB |
Output is correct |
8 |
Correct |
109 ms |
4452 KB |
Output is correct |
9 |
Correct |
111 ms |
4524 KB |
Output is correct |
10 |
Correct |
83 ms |
3392 KB |
Output is correct |
11 |
Correct |
83 ms |
3396 KB |
Output is correct |
12 |
Correct |
87 ms |
3424 KB |
Output is correct |
13 |
Correct |
87 ms |
3520 KB |
Output is correct |
14 |
Correct |
82 ms |
3496 KB |
Output is correct |
15 |
Correct |
80 ms |
3492 KB |
Output is correct |
16 |
Correct |
77 ms |
3476 KB |
Output is correct |
17 |
Correct |
82 ms |
3492 KB |
Output is correct |
18 |
Correct |
79 ms |
3444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
3 ms |
468 KB |
Output is correct |
10 |
Correct |
3 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
388 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
488 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
12 ms |
980 KB |
Output is correct |
20 |
Correct |
15 ms |
1016 KB |
Output is correct |
21 |
Correct |
14 ms |
1116 KB |
Output is correct |
22 |
Correct |
14 ms |
1024 KB |
Output is correct |
23 |
Correct |
15 ms |
984 KB |
Output is correct |
24 |
Correct |
13 ms |
980 KB |
Output is correct |
25 |
Correct |
13 ms |
1024 KB |
Output is correct |
26 |
Correct |
13 ms |
980 KB |
Output is correct |
27 |
Correct |
13 ms |
1028 KB |
Output is correct |
28 |
Correct |
18 ms |
1028 KB |
Output is correct |
29 |
Correct |
22 ms |
1360 KB |
Output is correct |
30 |
Correct |
60 ms |
2636 KB |
Output is correct |
31 |
Correct |
102 ms |
4492 KB |
Output is correct |
32 |
Correct |
106 ms |
4520 KB |
Output is correct |
33 |
Correct |
100 ms |
4524 KB |
Output is correct |
34 |
Correct |
106 ms |
4460 KB |
Output is correct |
35 |
Correct |
102 ms |
4416 KB |
Output is correct |
36 |
Correct |
109 ms |
4452 KB |
Output is correct |
37 |
Correct |
111 ms |
4524 KB |
Output is correct |
38 |
Correct |
83 ms |
3392 KB |
Output is correct |
39 |
Correct |
83 ms |
3396 KB |
Output is correct |
40 |
Correct |
87 ms |
3424 KB |
Output is correct |
41 |
Correct |
87 ms |
3520 KB |
Output is correct |
42 |
Correct |
82 ms |
3496 KB |
Output is correct |
43 |
Correct |
80 ms |
3492 KB |
Output is correct |
44 |
Correct |
77 ms |
3476 KB |
Output is correct |
45 |
Correct |
82 ms |
3492 KB |
Output is correct |
46 |
Correct |
79 ms |
3444 KB |
Output is correct |
47 |
Correct |
390 ms |
14772 KB |
Output is correct |
48 |
Correct |
1629 ms |
36776 KB |
Output is correct |
49 |
Correct |
1687 ms |
51168 KB |
Output is correct |
50 |
Correct |
1834 ms |
51172 KB |
Output is correct |
51 |
Correct |
1682 ms |
51172 KB |
Output is correct |
52 |
Correct |
1685 ms |
51328 KB |
Output is correct |
53 |
Correct |
1742 ms |
51076 KB |
Output is correct |
54 |
Correct |
1531 ms |
51316 KB |
Output is correct |
55 |
Correct |
1607 ms |
51344 KB |
Output is correct |
56 |
Correct |
1492 ms |
51464 KB |
Output is correct |
57 |
Correct |
1573 ms |
51424 KB |
Output is correct |
58 |
Correct |
1511 ms |
51304 KB |
Output is correct |
59 |
Correct |
1415 ms |
49980 KB |
Output is correct |
60 |
Correct |
1430 ms |
50028 KB |
Output is correct |
61 |
Correct |
1435 ms |
50024 KB |
Output is correct |
62 |
Correct |
1332 ms |
49744 KB |
Output is correct |
63 |
Correct |
1381 ms |
49840 KB |
Output is correct |
64 |
Correct |
1358 ms |
49848 KB |
Output is correct |
65 |
Correct |
1267 ms |
49704 KB |
Output is correct |
66 |
Correct |
1243 ms |
49768 KB |
Output is correct |
67 |
Correct |
1279 ms |
49632 KB |
Output is correct |