#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
const int MX = 1e6 + 10;
struct segtree{
int st[MX << 2], lz[MX << 2];
void prop(int id, int l, int r){
if(lz[id] == 0) return;
st[id] += lz[id];
if(l != r){
lz[id << 1] += lz[id];
lz[id << 1|1] += lz[id];
}
lz[id] = 0;
}
void upd(int id, int from, int to, int l, int r, int v){
if(to < from) return;
// if(id == 1) cout << "update " << from << " to " << to << " value " << v << '\n';
prop(id, l, r);
if(r < from || l > to) return;
if(from <= l && r <= to){
lz[id] += v;
prop(id, l, r);
}else{
int mid = l + r >> 1;
upd(id << 1, from, to, l, mid, v);
upd(id << 1|1, from, to, mid + 1, r, v);
st[id] = max(st[id << 1], st[id << 1|1]);
}
}
int que(int id, int from, int to, int l, int r){
prop(id, l, r);
if(r < from || l > to) return 0;
if(from <= l && r <= to){
return st[id];
}else{
int mid = l + r >> 1;
return max(
que(id << 1, from, to, l, mid),
que(id << 1|1, from, to, mid + 1, r)
);
}
}
} S;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V){
vector<pii> vec;
for(int i = 0; i < (int) A.size(); i++) vec.push_back({A[i], i});
for(int i = 0; i < (int) X.size(); i++) vec.push_back({V[i], X[i]});
sort(vec.begin(), vec.end());
vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
int M = vec.size();
for(int i = 0; i < (int) A.size(); i++){
int idx = lower_bound(vec.begin(), vec.end(), make_pair(A[i], i)) - vec.begin();
S.upd(1, idx, idx, 0, M - 1, i);
S.upd(1, idx + 1, M - 1, 0, M - 1, -1);
}
vector<int> pos = A, ans;
for(int i = 0; i < (int) X.size(); i++){
int prev_idx = lower_bound(vec.begin(), vec.end(), make_pair(pos[X[i]], X[i])) - vec.begin();
int curr_idx = lower_bound(vec.begin(), vec.end(), make_pair(V[i], X[i])) - vec.begin();
S.upd(1, prev_idx, prev_idx, 0, M - 1, -X[i]);
S.upd(1, prev_idx + 1, M - 1, 0, M - 1, 1);
S.upd(1, curr_idx, curr_idx, 0, M - 1, X[i]);
S.upd(1, curr_idx + 1, M - 1, 0, M - 1, -1);
ans.push_back(S.que(1, 0, M - 1, 0, M - 1));
pos[X[i]] = V[i];
}
return ans;
}
Compilation message
bubblesort2.cpp: In member function 'void segtree::upd(int, int, int, int, int, int)':
bubblesort2.cpp:34:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = l + r >> 1;
| ~~^~~
bubblesort2.cpp: In member function 'int segtree::que(int, int, int, int, int)':
bubblesort2.cpp:47:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int mid = l + r >> 1;
| ~~^~~
# |
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 |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
496 KB |
Output is correct |
6 |
Correct |
4 ms |
496 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
488 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
7 ms |
496 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
4 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 |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
496 KB |
Output is correct |
6 |
Correct |
4 ms |
496 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
488 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
7 ms |
496 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
16 ms |
980 KB |
Output is correct |
20 |
Correct |
18 ms |
980 KB |
Output is correct |
21 |
Correct |
18 ms |
928 KB |
Output is correct |
22 |
Correct |
17 ms |
980 KB |
Output is correct |
23 |
Correct |
17 ms |
980 KB |
Output is correct |
24 |
Correct |
17 ms |
980 KB |
Output is correct |
25 |
Correct |
17 ms |
992 KB |
Output is correct |
26 |
Correct |
16 ms |
980 KB |
Output is correct |
27 |
Correct |
18 ms |
980 KB |
Output is correct |
28 |
Correct |
15 ms |
912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1360 KB |
Output is correct |
2 |
Correct |
75 ms |
2884 KB |
Output is correct |
3 |
Correct |
149 ms |
4932 KB |
Output is correct |
4 |
Correct |
125 ms |
4968 KB |
Output is correct |
5 |
Correct |
122 ms |
4984 KB |
Output is correct |
6 |
Correct |
125 ms |
4940 KB |
Output is correct |
7 |
Correct |
119 ms |
4928 KB |
Output is correct |
8 |
Correct |
133 ms |
4860 KB |
Output is correct |
9 |
Correct |
128 ms |
4944 KB |
Output is correct |
10 |
Correct |
118 ms |
3904 KB |
Output is correct |
11 |
Correct |
97 ms |
3892 KB |
Output is correct |
12 |
Correct |
96 ms |
3928 KB |
Output is correct |
13 |
Correct |
101 ms |
3904 KB |
Output is correct |
14 |
Correct |
105 ms |
3876 KB |
Output is correct |
15 |
Correct |
96 ms |
3900 KB |
Output is correct |
16 |
Correct |
90 ms |
3880 KB |
Output is correct |
17 |
Correct |
97 ms |
3924 KB |
Output is correct |
18 |
Correct |
96 ms |
3880 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 |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
496 KB |
Output is correct |
6 |
Correct |
4 ms |
496 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
7 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
488 KB |
Output is correct |
11 |
Correct |
5 ms |
492 KB |
Output is correct |
12 |
Correct |
7 ms |
496 KB |
Output is correct |
13 |
Correct |
4 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
468 KB |
Output is correct |
15 |
Correct |
4 ms |
468 KB |
Output is correct |
16 |
Correct |
4 ms |
468 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
4 ms |
468 KB |
Output is correct |
19 |
Correct |
16 ms |
980 KB |
Output is correct |
20 |
Correct |
18 ms |
980 KB |
Output is correct |
21 |
Correct |
18 ms |
928 KB |
Output is correct |
22 |
Correct |
17 ms |
980 KB |
Output is correct |
23 |
Correct |
17 ms |
980 KB |
Output is correct |
24 |
Correct |
17 ms |
980 KB |
Output is correct |
25 |
Correct |
17 ms |
992 KB |
Output is correct |
26 |
Correct |
16 ms |
980 KB |
Output is correct |
27 |
Correct |
18 ms |
980 KB |
Output is correct |
28 |
Correct |
15 ms |
912 KB |
Output is correct |
29 |
Correct |
23 ms |
1360 KB |
Output is correct |
30 |
Correct |
75 ms |
2884 KB |
Output is correct |
31 |
Correct |
149 ms |
4932 KB |
Output is correct |
32 |
Correct |
125 ms |
4968 KB |
Output is correct |
33 |
Correct |
122 ms |
4984 KB |
Output is correct |
34 |
Correct |
125 ms |
4940 KB |
Output is correct |
35 |
Correct |
119 ms |
4928 KB |
Output is correct |
36 |
Correct |
133 ms |
4860 KB |
Output is correct |
37 |
Correct |
128 ms |
4944 KB |
Output is correct |
38 |
Correct |
118 ms |
3904 KB |
Output is correct |
39 |
Correct |
97 ms |
3892 KB |
Output is correct |
40 |
Correct |
96 ms |
3928 KB |
Output is correct |
41 |
Correct |
101 ms |
3904 KB |
Output is correct |
42 |
Correct |
105 ms |
3876 KB |
Output is correct |
43 |
Correct |
96 ms |
3900 KB |
Output is correct |
44 |
Correct |
90 ms |
3880 KB |
Output is correct |
45 |
Correct |
97 ms |
3924 KB |
Output is correct |
46 |
Correct |
96 ms |
3880 KB |
Output is correct |
47 |
Correct |
471 ms |
16344 KB |
Output is correct |
48 |
Correct |
2009 ms |
40396 KB |
Output is correct |
49 |
Correct |
1995 ms |
55388 KB |
Output is correct |
50 |
Correct |
2316 ms |
55232 KB |
Output is correct |
51 |
Correct |
2037 ms |
55188 KB |
Output is correct |
52 |
Correct |
2013 ms |
55284 KB |
Output is correct |
53 |
Correct |
2491 ms |
55180 KB |
Output is correct |
54 |
Correct |
1924 ms |
55384 KB |
Output is correct |
55 |
Correct |
2021 ms |
55364 KB |
Output is correct |
56 |
Correct |
1883 ms |
55284 KB |
Output is correct |
57 |
Correct |
2074 ms |
55384 KB |
Output is correct |
58 |
Correct |
1818 ms |
55368 KB |
Output is correct |
59 |
Correct |
1707 ms |
54012 KB |
Output is correct |
60 |
Correct |
1761 ms |
54156 KB |
Output is correct |
61 |
Correct |
1715 ms |
54032 KB |
Output is correct |
62 |
Correct |
1651 ms |
53916 KB |
Output is correct |
63 |
Correct |
1620 ms |
53884 KB |
Output is correct |
64 |
Correct |
1730 ms |
53848 KB |
Output is correct |
65 |
Correct |
1556 ms |
53600 KB |
Output is correct |
66 |
Correct |
1559 ms |
53752 KB |
Output is correct |
67 |
Correct |
1526 ms |
53720 KB |
Output is correct |