#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#pragma g++ optimize("Ofast")
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];
}
int loc(pair<int, int> p) {return lower_bound(D.begin(), D.end(), p) - D.begin();}
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
int Q = X.size();
int n = A.size();
D.reserve(Q + n);
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 < n; i++) {
int ind = loc({A[i], i});
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 = loc({A[X[i]], X[i]});
add(1, 0, D.size(), ind, ind + 1, -X[i]);
add(1, 0, D.size(), ind + 1, D.size(), +1);
ind = loc({V[i], X[i]});
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:4: warning: ignoring '#pragma g ' [-Wunknown-pragmas]
4 | #pragma g++ optimize("Ofast")
|
bubblesort2.cpp: In function 'void add(int, int, int, int, int, int)':
bubblesort2.cpp:15:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
15 | int m = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
448 KB |
Output is correct |
10 |
Correct |
4 ms |
444 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
480 KB |
Output is correct |
13 |
Correct |
3 ms |
452 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
444 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 |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
448 KB |
Output is correct |
10 |
Correct |
4 ms |
444 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
480 KB |
Output is correct |
13 |
Correct |
3 ms |
452 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
444 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
15 ms |
980 KB |
Output is correct |
20 |
Correct |
17 ms |
1080 KB |
Output is correct |
21 |
Correct |
15 ms |
1032 KB |
Output is correct |
22 |
Correct |
15 ms |
1084 KB |
Output is correct |
23 |
Correct |
14 ms |
1004 KB |
Output is correct |
24 |
Correct |
15 ms |
1036 KB |
Output is correct |
25 |
Correct |
14 ms |
1036 KB |
Output is correct |
26 |
Correct |
15 ms |
956 KB |
Output is correct |
27 |
Correct |
13 ms |
980 KB |
Output is correct |
28 |
Correct |
14 ms |
1028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1364 KB |
Output is correct |
2 |
Correct |
62 ms |
2808 KB |
Output is correct |
3 |
Correct |
104 ms |
4788 KB |
Output is correct |
4 |
Correct |
104 ms |
4724 KB |
Output is correct |
5 |
Correct |
102 ms |
4668 KB |
Output is correct |
6 |
Correct |
102 ms |
4728 KB |
Output is correct |
7 |
Correct |
107 ms |
4780 KB |
Output is correct |
8 |
Correct |
102 ms |
4672 KB |
Output is correct |
9 |
Correct |
100 ms |
4684 KB |
Output is correct |
10 |
Correct |
83 ms |
3676 KB |
Output is correct |
11 |
Correct |
84 ms |
3728 KB |
Output is correct |
12 |
Correct |
89 ms |
3744 KB |
Output is correct |
13 |
Correct |
84 ms |
3752 KB |
Output is correct |
14 |
Correct |
98 ms |
3744 KB |
Output is correct |
15 |
Correct |
81 ms |
3680 KB |
Output is correct |
16 |
Correct |
81 ms |
3660 KB |
Output is correct |
17 |
Correct |
81 ms |
3692 KB |
Output is correct |
18 |
Correct |
82 ms |
3628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
492 KB |
Output is correct |
6 |
Correct |
4 ms |
492 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
448 KB |
Output is correct |
10 |
Correct |
4 ms |
444 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
480 KB |
Output is correct |
13 |
Correct |
3 ms |
452 KB |
Output is correct |
14 |
Correct |
3 ms |
468 KB |
Output is correct |
15 |
Correct |
3 ms |
468 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
444 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
15 ms |
980 KB |
Output is correct |
20 |
Correct |
17 ms |
1080 KB |
Output is correct |
21 |
Correct |
15 ms |
1032 KB |
Output is correct |
22 |
Correct |
15 ms |
1084 KB |
Output is correct |
23 |
Correct |
14 ms |
1004 KB |
Output is correct |
24 |
Correct |
15 ms |
1036 KB |
Output is correct |
25 |
Correct |
14 ms |
1036 KB |
Output is correct |
26 |
Correct |
15 ms |
956 KB |
Output is correct |
27 |
Correct |
13 ms |
980 KB |
Output is correct |
28 |
Correct |
14 ms |
1028 KB |
Output is correct |
29 |
Correct |
19 ms |
1364 KB |
Output is correct |
30 |
Correct |
62 ms |
2808 KB |
Output is correct |
31 |
Correct |
104 ms |
4788 KB |
Output is correct |
32 |
Correct |
104 ms |
4724 KB |
Output is correct |
33 |
Correct |
102 ms |
4668 KB |
Output is correct |
34 |
Correct |
102 ms |
4728 KB |
Output is correct |
35 |
Correct |
107 ms |
4780 KB |
Output is correct |
36 |
Correct |
102 ms |
4672 KB |
Output is correct |
37 |
Correct |
100 ms |
4684 KB |
Output is correct |
38 |
Correct |
83 ms |
3676 KB |
Output is correct |
39 |
Correct |
84 ms |
3728 KB |
Output is correct |
40 |
Correct |
89 ms |
3744 KB |
Output is correct |
41 |
Correct |
84 ms |
3752 KB |
Output is correct |
42 |
Correct |
98 ms |
3744 KB |
Output is correct |
43 |
Correct |
81 ms |
3680 KB |
Output is correct |
44 |
Correct |
81 ms |
3660 KB |
Output is correct |
45 |
Correct |
81 ms |
3692 KB |
Output is correct |
46 |
Correct |
82 ms |
3628 KB |
Output is correct |
47 |
Correct |
378 ms |
15060 KB |
Output is correct |
48 |
Correct |
1526 ms |
36920 KB |
Output is correct |
49 |
Correct |
1696 ms |
38812 KB |
Output is correct |
50 |
Correct |
1773 ms |
38776 KB |
Output is correct |
51 |
Correct |
1717 ms |
38740 KB |
Output is correct |
52 |
Correct |
1646 ms |
38876 KB |
Output is correct |
53 |
Correct |
1659 ms |
38772 KB |
Output is correct |
54 |
Correct |
1518 ms |
38768 KB |
Output is correct |
55 |
Correct |
1636 ms |
38856 KB |
Output is correct |
56 |
Correct |
1530 ms |
38736 KB |
Output is correct |
57 |
Correct |
1613 ms |
38736 KB |
Output is correct |
58 |
Correct |
1523 ms |
38796 KB |
Output is correct |
59 |
Correct |
1406 ms |
38832 KB |
Output is correct |
60 |
Correct |
1389 ms |
38764 KB |
Output is correct |
61 |
Correct |
1371 ms |
38760 KB |
Output is correct |
62 |
Correct |
1360 ms |
38828 KB |
Output is correct |
63 |
Correct |
1338 ms |
38768 KB |
Output is correct |
64 |
Correct |
1379 ms |
38768 KB |
Output is correct |
65 |
Correct |
1334 ms |
39012 KB |
Output is correct |
66 |
Correct |
1337 ms |
39072 KB |
Output is correct |
67 |
Correct |
1374 ms |
39056 KB |
Output is correct |