#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
const int MX = 5e5 + 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 |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
448 KB |
Output is correct |
6 |
Correct |
5 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
452 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
456 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 |
536 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
448 KB |
Output is correct |
6 |
Correct |
5 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
452 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
456 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 |
536 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
15 ms |
1108 KB |
Output is correct |
20 |
Correct |
17 ms |
1096 KB |
Output is correct |
21 |
Correct |
17 ms |
1108 KB |
Output is correct |
22 |
Correct |
17 ms |
1180 KB |
Output is correct |
23 |
Correct |
16 ms |
1180 KB |
Output is correct |
24 |
Correct |
16 ms |
1100 KB |
Output is correct |
25 |
Correct |
16 ms |
1080 KB |
Output is correct |
26 |
Correct |
16 ms |
1108 KB |
Output is correct |
27 |
Correct |
15 ms |
1108 KB |
Output is correct |
28 |
Correct |
16 ms |
1072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1488 KB |
Output is correct |
2 |
Correct |
69 ms |
3140 KB |
Output is correct |
3 |
Correct |
126 ms |
5440 KB |
Output is correct |
4 |
Correct |
121 ms |
5428 KB |
Output is correct |
5 |
Correct |
128 ms |
5548 KB |
Output is correct |
6 |
Correct |
137 ms |
5444 KB |
Output is correct |
7 |
Correct |
120 ms |
5552 KB |
Output is correct |
8 |
Correct |
122 ms |
5568 KB |
Output is correct |
9 |
Correct |
130 ms |
5464 KB |
Output is correct |
10 |
Correct |
101 ms |
4588 KB |
Output is correct |
11 |
Correct |
99 ms |
4572 KB |
Output is correct |
12 |
Correct |
99 ms |
4500 KB |
Output is correct |
13 |
Correct |
99 ms |
4636 KB |
Output is correct |
14 |
Correct |
97 ms |
4476 KB |
Output is correct |
15 |
Correct |
97 ms |
4532 KB |
Output is correct |
16 |
Correct |
94 ms |
4528 KB |
Output is correct |
17 |
Correct |
96 ms |
4556 KB |
Output is correct |
18 |
Correct |
96 ms |
4504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
400 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
5 ms |
468 KB |
Output is correct |
4 |
Correct |
5 ms |
468 KB |
Output is correct |
5 |
Correct |
5 ms |
448 KB |
Output is correct |
6 |
Correct |
5 ms |
452 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
452 KB |
Output is correct |
10 |
Correct |
6 ms |
468 KB |
Output is correct |
11 |
Correct |
4 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
456 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 |
536 KB |
Output is correct |
17 |
Correct |
4 ms |
468 KB |
Output is correct |
18 |
Correct |
5 ms |
468 KB |
Output is correct |
19 |
Correct |
15 ms |
1108 KB |
Output is correct |
20 |
Correct |
17 ms |
1096 KB |
Output is correct |
21 |
Correct |
17 ms |
1108 KB |
Output is correct |
22 |
Correct |
17 ms |
1180 KB |
Output is correct |
23 |
Correct |
16 ms |
1180 KB |
Output is correct |
24 |
Correct |
16 ms |
1100 KB |
Output is correct |
25 |
Correct |
16 ms |
1080 KB |
Output is correct |
26 |
Correct |
16 ms |
1108 KB |
Output is correct |
27 |
Correct |
15 ms |
1108 KB |
Output is correct |
28 |
Correct |
16 ms |
1072 KB |
Output is correct |
29 |
Correct |
25 ms |
1488 KB |
Output is correct |
30 |
Correct |
69 ms |
3140 KB |
Output is correct |
31 |
Correct |
126 ms |
5440 KB |
Output is correct |
32 |
Correct |
121 ms |
5428 KB |
Output is correct |
33 |
Correct |
128 ms |
5548 KB |
Output is correct |
34 |
Correct |
137 ms |
5444 KB |
Output is correct |
35 |
Correct |
120 ms |
5552 KB |
Output is correct |
36 |
Correct |
122 ms |
5568 KB |
Output is correct |
37 |
Correct |
130 ms |
5464 KB |
Output is correct |
38 |
Correct |
101 ms |
4588 KB |
Output is correct |
39 |
Correct |
99 ms |
4572 KB |
Output is correct |
40 |
Correct |
99 ms |
4500 KB |
Output is correct |
41 |
Correct |
99 ms |
4636 KB |
Output is correct |
42 |
Correct |
97 ms |
4476 KB |
Output is correct |
43 |
Correct |
97 ms |
4532 KB |
Output is correct |
44 |
Correct |
94 ms |
4528 KB |
Output is correct |
45 |
Correct |
96 ms |
4556 KB |
Output is correct |
46 |
Correct |
96 ms |
4504 KB |
Output is correct |
47 |
Correct |
455 ms |
20080 KB |
Output is correct |
48 |
Runtime error |
288 ms |
50404 KB |
Execution killed with signal 11 |
49 |
Halted |
0 ms |
0 KB |
- |