#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAX = 2000020;
int n, ans[MAX];
struct segtree {
pair<int, int> st[MAX << 2];
void build(int id, int l, int r) {
st[id] = make_pair(-INF, INF);
if (l == r) {
st[id] = make_pair(0, 0);
return;
}
int mid = l + r >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
}
void update(int id, int l, int r) {
if (st[id].first > r) st[id] = make_pair(r, r); else
if (st[id].second < l) st[id] = make_pair(l, l); else
st[id] = make_pair(max(l, st[id].first), min(r, st[id].second));
}
void push(int id) {
update(id << 1, st[id].first, st[id].second);
update(id << 1 | 1, st[id].first, st[id].second); st[id] = make_pair(-INF, INF);
}
void update(int id, int l, int r, int u, int v, int t, int newH) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
if (!t) update(id, newH, INF);
else update(id, -INF, newH);
return;
}
int mid = l + r >> 1; push(id);
update(id << 1, l, mid, u, v, t, newH);
update(id << 1 | 1, mid + 1, r, u, v, t, newH);
}
} tree;
void magic(int id, int l, int r) {
if (l == r) {
ans[l] = tree.st[id].first;
return;
}
int mid = l + r >> 1; tree.push(id);
magic(id << 1, l, mid); magic(id << 1 | 1, mid + 1, r);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
tree.build(1, 1, n);
for (int i = 0; i < k; i++) {
tree.update(1, 1, n, left[i] + 1, right[i] + 1, op[i] - 1, height[i]);
}
magic(1, 1, n);
for (int i = 0; i < n; ++i)
finalHeight[i] = ans[i + 1];
}
Compilation message
wall.cpp: In member function 'void segtree::build(int, int, int)':
wall.cpp:18:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
18 | int mid = l + r >> 1;
| ~~^~~
wall.cpp: In member function 'void segtree::update(int, int, int, int, int, int, int)':
wall.cpp:41:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int mid = l + r >> 1; push(id);
| ~~^~~
wall.cpp: In function 'void magic(int, int, int)':
wall.cpp:53:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
53 | int mid = l + r >> 1; tree.push(id);
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
836 KB |
Output is correct |
5 |
Correct |
4 ms |
828 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
108 ms |
13876 KB |
Output is correct |
3 |
Correct |
117 ms |
8036 KB |
Output is correct |
4 |
Correct |
303 ms |
16972 KB |
Output is correct |
5 |
Correct |
206 ms |
17564 KB |
Output is correct |
6 |
Correct |
224 ms |
17524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
320 KB |
Output is correct |
4 |
Correct |
5 ms |
852 KB |
Output is correct |
5 |
Correct |
5 ms |
772 KB |
Output is correct |
6 |
Correct |
4 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
100 ms |
13944 KB |
Output is correct |
9 |
Correct |
109 ms |
8044 KB |
Output is correct |
10 |
Correct |
377 ms |
16988 KB |
Output is correct |
11 |
Correct |
198 ms |
17488 KB |
Output is correct |
12 |
Correct |
195 ms |
17496 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
117 ms |
13964 KB |
Output is correct |
15 |
Correct |
26 ms |
2124 KB |
Output is correct |
16 |
Correct |
429 ms |
17232 KB |
Output is correct |
17 |
Correct |
208 ms |
17352 KB |
Output is correct |
18 |
Correct |
246 ms |
17264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
832 KB |
Output is correct |
5 |
Correct |
4 ms |
836 KB |
Output is correct |
6 |
Correct |
4 ms |
828 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
104 ms |
13924 KB |
Output is correct |
9 |
Correct |
109 ms |
8040 KB |
Output is correct |
10 |
Correct |
323 ms |
16956 KB |
Output is correct |
11 |
Correct |
212 ms |
17488 KB |
Output is correct |
12 |
Correct |
190 ms |
17484 KB |
Output is correct |
13 |
Correct |
1 ms |
216 KB |
Output is correct |
14 |
Correct |
109 ms |
13936 KB |
Output is correct |
15 |
Correct |
23 ms |
2064 KB |
Output is correct |
16 |
Correct |
424 ms |
17228 KB |
Output is correct |
17 |
Correct |
237 ms |
17228 KB |
Output is correct |
18 |
Correct |
202 ms |
17268 KB |
Output is correct |
19 |
Correct |
473 ms |
72720 KB |
Output is correct |
20 |
Correct |
468 ms |
70260 KB |
Output is correct |
21 |
Correct |
461 ms |
72724 KB |
Output is correct |
22 |
Correct |
458 ms |
70412 KB |
Output is correct |
23 |
Correct |
461 ms |
70276 KB |
Output is correct |
24 |
Correct |
546 ms |
70292 KB |
Output is correct |
25 |
Correct |
458 ms |
70404 KB |
Output is correct |
26 |
Correct |
495 ms |
72780 KB |
Output is correct |
27 |
Correct |
469 ms |
72844 KB |
Output is correct |
28 |
Correct |
489 ms |
70260 KB |
Output is correct |
29 |
Correct |
487 ms |
70308 KB |
Output is correct |
30 |
Correct |
456 ms |
70244 KB |
Output is correct |