#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ii = pair <int, int>;
using vi = vector <int>;
const int N = 4e6 + 5;
int mx, lz[N], Max[N];
const int inf = 4e6;
void update(int u, int v, int val, int s = 1, int l = 0, int r = mx - 1){
if (u <= l && r <= v){
Max[s] += val, lz[s] += val;
return;
}
int mid = l + r >> 1;
if (mid >= u) update(u, v, val, s << 1, l, mid);
if (mid < v) update(u, v, val, s << 1 | 1, mid + 1, r);
Max[s] = max(Max[s << 1], Max[s << 1 | 1]) + lz[s];
}
vi countScans(vi a, vi x, vi y){
int n = a.size(), q = x.size(); vector <ii> sr;
#define all(x) (x).begin(), (x).end()
#define fd(sr, x) (lower_bound(sr.begin(), sr.end(), x) - sr.begin())
#define uq(sr) (sr).erase(unique(all((sr))), (sr).end())
#define szv(v) (int((v).size()))
for (int i = 0; i < n; ++ i) sr.pb({a[i], i});
for (int i = 0; i < q; ++ i) sr.pb({y[i], x[i]});
sort(all(sr)); uq(sr); mx = szv(sr);
for (int i = 1; i <= 4 * mx; ++ i) Max[i] = -inf, lz[i] = 0;
auto fix = [&](int i, int f) -> void {
ii x = {a[i], i}; int T = fd(sr, x);
update(T, T, f * (inf + i));
update(T, mx - 1, -f);
};
vi ans;
for (int i = 0; i < n; ++ i) fix(i, 1);
for (int i = 0; i < q; ++ i){
fix(x[i], -1); a[x[i]] = y[i];
fix(x[i], 1); ans.pb(Max[1] + 1);
}
return ans;
}
Compilation message
bubblesort2.cpp: In function 'void update(int, int, int, int, int, int)':
bubblesort2.cpp:19:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
10 ms |
1112 KB |
Output is correct |
20 |
Correct |
11 ms |
1372 KB |
Output is correct |
21 |
Correct |
11 ms |
1368 KB |
Output is correct |
22 |
Correct |
12 ms |
1372 KB |
Output is correct |
23 |
Correct |
11 ms |
1240 KB |
Output is correct |
24 |
Correct |
13 ms |
1160 KB |
Output is correct |
25 |
Correct |
11 ms |
1112 KB |
Output is correct |
26 |
Correct |
12 ms |
1188 KB |
Output is correct |
27 |
Correct |
12 ms |
1116 KB |
Output is correct |
28 |
Correct |
12 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1772 KB |
Output is correct |
2 |
Correct |
46 ms |
3784 KB |
Output is correct |
3 |
Correct |
84 ms |
5896 KB |
Output is correct |
4 |
Correct |
87 ms |
5900 KB |
Output is correct |
5 |
Correct |
78 ms |
5880 KB |
Output is correct |
6 |
Correct |
80 ms |
5828 KB |
Output is correct |
7 |
Correct |
82 ms |
5832 KB |
Output is correct |
8 |
Correct |
77 ms |
5684 KB |
Output is correct |
9 |
Correct |
77 ms |
5832 KB |
Output is correct |
10 |
Correct |
60 ms |
4552 KB |
Output is correct |
11 |
Correct |
67 ms |
4292 KB |
Output is correct |
12 |
Correct |
63 ms |
4304 KB |
Output is correct |
13 |
Correct |
59 ms |
4548 KB |
Output is correct |
14 |
Correct |
57 ms |
4348 KB |
Output is correct |
15 |
Correct |
68 ms |
4332 KB |
Output is correct |
16 |
Correct |
57 ms |
4548 KB |
Output is correct |
17 |
Correct |
54 ms |
4552 KB |
Output is correct |
18 |
Correct |
53 ms |
4552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
604 KB |
Output is correct |
4 |
Correct |
3 ms |
604 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
3 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
668 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
600 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
10 ms |
1112 KB |
Output is correct |
20 |
Correct |
11 ms |
1372 KB |
Output is correct |
21 |
Correct |
11 ms |
1368 KB |
Output is correct |
22 |
Correct |
12 ms |
1372 KB |
Output is correct |
23 |
Correct |
11 ms |
1240 KB |
Output is correct |
24 |
Correct |
13 ms |
1160 KB |
Output is correct |
25 |
Correct |
11 ms |
1112 KB |
Output is correct |
26 |
Correct |
12 ms |
1188 KB |
Output is correct |
27 |
Correct |
12 ms |
1116 KB |
Output is correct |
28 |
Correct |
12 ms |
1116 KB |
Output is correct |
29 |
Correct |
16 ms |
1772 KB |
Output is correct |
30 |
Correct |
46 ms |
3784 KB |
Output is correct |
31 |
Correct |
84 ms |
5896 KB |
Output is correct |
32 |
Correct |
87 ms |
5900 KB |
Output is correct |
33 |
Correct |
78 ms |
5880 KB |
Output is correct |
34 |
Correct |
80 ms |
5828 KB |
Output is correct |
35 |
Correct |
82 ms |
5832 KB |
Output is correct |
36 |
Correct |
77 ms |
5684 KB |
Output is correct |
37 |
Correct |
77 ms |
5832 KB |
Output is correct |
38 |
Correct |
60 ms |
4552 KB |
Output is correct |
39 |
Correct |
67 ms |
4292 KB |
Output is correct |
40 |
Correct |
63 ms |
4304 KB |
Output is correct |
41 |
Correct |
59 ms |
4548 KB |
Output is correct |
42 |
Correct |
57 ms |
4348 KB |
Output is correct |
43 |
Correct |
68 ms |
4332 KB |
Output is correct |
44 |
Correct |
57 ms |
4548 KB |
Output is correct |
45 |
Correct |
54 ms |
4552 KB |
Output is correct |
46 |
Correct |
53 ms |
4552 KB |
Output is correct |
47 |
Correct |
302 ms |
16856 KB |
Output is correct |
48 |
Correct |
1110 ms |
50856 KB |
Output is correct |
49 |
Correct |
1261 ms |
55216 KB |
Output is correct |
50 |
Correct |
1269 ms |
55216 KB |
Output is correct |
51 |
Correct |
1266 ms |
55216 KB |
Output is correct |
52 |
Correct |
1266 ms |
55240 KB |
Output is correct |
53 |
Correct |
1249 ms |
55220 KB |
Output is correct |
54 |
Correct |
1152 ms |
55216 KB |
Output is correct |
55 |
Correct |
1232 ms |
55232 KB |
Output is correct |
56 |
Correct |
1233 ms |
55304 KB |
Output is correct |
57 |
Correct |
1225 ms |
55212 KB |
Output is correct |
58 |
Correct |
1144 ms |
55300 KB |
Output is correct |
59 |
Correct |
1046 ms |
51376 KB |
Output is correct |
60 |
Correct |
1035 ms |
51376 KB |
Output is correct |
61 |
Correct |
1000 ms |
51376 KB |
Output is correct |
62 |
Correct |
946 ms |
49328 KB |
Output is correct |
63 |
Correct |
918 ms |
49328 KB |
Output is correct |
64 |
Correct |
919 ms |
49324 KB |
Output is correct |
65 |
Correct |
856 ms |
47276 KB |
Output is correct |
66 |
Correct |
856 ms |
47304 KB |
Output is correct |
67 |
Correct |
896 ms |
47280 KB |
Output is correct |