#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();
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 < 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:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < A.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
444 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
448 KB |
Output is correct |
8 |
Correct |
3 ms |
488 KB |
Output is correct |
9 |
Correct |
3 ms |
484 KB |
Output is correct |
10 |
Correct |
3 ms |
444 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
448 KB |
Output is correct |
16 |
Correct |
3 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
444 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
448 KB |
Output is correct |
8 |
Correct |
3 ms |
488 KB |
Output is correct |
9 |
Correct |
3 ms |
484 KB |
Output is correct |
10 |
Correct |
3 ms |
444 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
448 KB |
Output is correct |
16 |
Correct |
3 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
13 ms |
1008 KB |
Output is correct |
20 |
Correct |
14 ms |
1104 KB |
Output is correct |
21 |
Correct |
14 ms |
1096 KB |
Output is correct |
22 |
Correct |
14 ms |
1052 KB |
Output is correct |
23 |
Correct |
14 ms |
1072 KB |
Output is correct |
24 |
Correct |
14 ms |
1108 KB |
Output is correct |
25 |
Correct |
14 ms |
1092 KB |
Output is correct |
26 |
Correct |
13 ms |
1108 KB |
Output is correct |
27 |
Correct |
16 ms |
1092 KB |
Output is correct |
28 |
Correct |
14 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
1404 KB |
Output is correct |
2 |
Correct |
57 ms |
2800 KB |
Output is correct |
3 |
Correct |
136 ms |
4872 KB |
Output is correct |
4 |
Correct |
105 ms |
4712 KB |
Output is correct |
5 |
Correct |
107 ms |
4688 KB |
Output is correct |
6 |
Correct |
134 ms |
4784 KB |
Output is correct |
7 |
Correct |
101 ms |
4716 KB |
Output is correct |
8 |
Correct |
101 ms |
4784 KB |
Output is correct |
9 |
Correct |
120 ms |
4808 KB |
Output is correct |
10 |
Correct |
95 ms |
3680 KB |
Output is correct |
11 |
Correct |
85 ms |
3732 KB |
Output is correct |
12 |
Correct |
85 ms |
3764 KB |
Output is correct |
13 |
Correct |
83 ms |
3728 KB |
Output is correct |
14 |
Correct |
110 ms |
3764 KB |
Output is correct |
15 |
Correct |
86 ms |
3660 KB |
Output is correct |
16 |
Correct |
78 ms |
3756 KB |
Output is correct |
17 |
Correct |
79 ms |
3692 KB |
Output is correct |
18 |
Correct |
78 ms |
3760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
444 KB |
Output is correct |
6 |
Correct |
3 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
448 KB |
Output is correct |
8 |
Correct |
3 ms |
488 KB |
Output is correct |
9 |
Correct |
3 ms |
484 KB |
Output is correct |
10 |
Correct |
3 ms |
444 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
5 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
448 KB |
Output is correct |
16 |
Correct |
3 ms |
448 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
13 ms |
1008 KB |
Output is correct |
20 |
Correct |
14 ms |
1104 KB |
Output is correct |
21 |
Correct |
14 ms |
1096 KB |
Output is correct |
22 |
Correct |
14 ms |
1052 KB |
Output is correct |
23 |
Correct |
14 ms |
1072 KB |
Output is correct |
24 |
Correct |
14 ms |
1108 KB |
Output is correct |
25 |
Correct |
14 ms |
1092 KB |
Output is correct |
26 |
Correct |
13 ms |
1108 KB |
Output is correct |
27 |
Correct |
16 ms |
1092 KB |
Output is correct |
28 |
Correct |
14 ms |
1108 KB |
Output is correct |
29 |
Correct |
19 ms |
1404 KB |
Output is correct |
30 |
Correct |
57 ms |
2800 KB |
Output is correct |
31 |
Correct |
136 ms |
4872 KB |
Output is correct |
32 |
Correct |
105 ms |
4712 KB |
Output is correct |
33 |
Correct |
107 ms |
4688 KB |
Output is correct |
34 |
Correct |
134 ms |
4784 KB |
Output is correct |
35 |
Correct |
101 ms |
4716 KB |
Output is correct |
36 |
Correct |
101 ms |
4784 KB |
Output is correct |
37 |
Correct |
120 ms |
4808 KB |
Output is correct |
38 |
Correct |
95 ms |
3680 KB |
Output is correct |
39 |
Correct |
85 ms |
3732 KB |
Output is correct |
40 |
Correct |
85 ms |
3764 KB |
Output is correct |
41 |
Correct |
83 ms |
3728 KB |
Output is correct |
42 |
Correct |
110 ms |
3764 KB |
Output is correct |
43 |
Correct |
86 ms |
3660 KB |
Output is correct |
44 |
Correct |
78 ms |
3756 KB |
Output is correct |
45 |
Correct |
79 ms |
3692 KB |
Output is correct |
46 |
Correct |
78 ms |
3760 KB |
Output is correct |
47 |
Correct |
411 ms |
15196 KB |
Output is correct |
48 |
Correct |
1532 ms |
37144 KB |
Output is correct |
49 |
Correct |
1820 ms |
41860 KB |
Output is correct |
50 |
Correct |
1806 ms |
41932 KB |
Output is correct |
51 |
Correct |
1705 ms |
41820 KB |
Output is correct |
52 |
Correct |
1769 ms |
41852 KB |
Output is correct |
53 |
Correct |
1664 ms |
41940 KB |
Output is correct |
54 |
Correct |
1561 ms |
41856 KB |
Output is correct |
55 |
Correct |
1633 ms |
41860 KB |
Output is correct |
56 |
Correct |
1555 ms |
41856 KB |
Output is correct |
57 |
Correct |
1670 ms |
41904 KB |
Output is correct |
58 |
Correct |
1570 ms |
41908 KB |
Output is correct |
59 |
Correct |
1429 ms |
41596 KB |
Output is correct |
60 |
Correct |
1427 ms |
41216 KB |
Output is correct |
61 |
Correct |
1380 ms |
40856 KB |
Output is correct |
62 |
Correct |
1341 ms |
40556 KB |
Output is correct |
63 |
Correct |
1372 ms |
40188 KB |
Output is correct |
64 |
Correct |
1397 ms |
39908 KB |
Output is correct |
65 |
Correct |
1237 ms |
39588 KB |
Output is correct |
66 |
Correct |
1328 ms |
39164 KB |
Output is correct |
67 |
Correct |
1335 ms |
38776 KB |
Output is correct |