#include <vector>
#include <iostream>
int clamp(int low, int high, int x) {
if (x < low) return low;
if (x > high) return high;
return x;
}
struct Req {
int min = 0;
int max = 2'000'000'000;
Req operator*(Req rhs) const {
return {
.min = clamp(min, max, rhs.min),
.max = clamp(min, max, rhs.max),
};
}
};
struct SegmentTree {
std::vector<Req> values;
int offset;
explicit SegmentTree(int o) : values(2 * o, {0, 0}), offset(o) {}
void push(int v) {
values[2 * v] = values[v] * values[2 * v];
values[2 * v + 1] = values[v] * values[2 * v + 1];
values[v] = Req{};
}
void update(int l, int r, Req upd) { update(l, r, upd, 1, 0, offset); }
void update(int l, int r, Req upd, int v, int s, int e) {
if (e <= l || r <= s) {
return;
} else if (l <= s && e <= r) {
values[v] = upd * values[v];
} else {
int m = (s + e) / 2;
push(v);
update(l, r, upd, 2 * v, s, m);
update(l, r, upd, 2 * v + 1, m, e);
values[v] = Req{};
}
}
void canonicalise() {
for (int i = 1; i < offset; i++) push(i);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[],
int finalHeight[]) {
int o = 1;
while (o < n) o *= 2;
SegmentTree st(o);
for (int i = 0; i < k; i++) {
int l = left[i];
int r = right[i] + 1;
Req upd;
if (op[i] == 1) upd.min = height[i];
if (op[i] == 2) upd.max = height[i];
st.update(l, r, upd);
}
st.canonicalise();
for (int i = 0; i < n; i++) finalHeight[i] = st.values[i + o].min;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 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 |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
108 ms |
13952 KB |
Output is correct |
3 |
Correct |
152 ms |
7912 KB |
Output is correct |
4 |
Correct |
374 ms |
20196 KB |
Output is correct |
5 |
Correct |
230 ms |
20632 KB |
Output is correct |
6 |
Correct |
229 ms |
19096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
109 ms |
13852 KB |
Output is correct |
9 |
Correct |
153 ms |
7920 KB |
Output is correct |
10 |
Correct |
366 ms |
20172 KB |
Output is correct |
11 |
Correct |
230 ms |
20684 KB |
Output is correct |
12 |
Correct |
231 ms |
19328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
111 ms |
13892 KB |
Output is correct |
15 |
Correct |
25 ms |
1896 KB |
Output is correct |
16 |
Correct |
462 ms |
20208 KB |
Output is correct |
17 |
Correct |
255 ms |
19516 KB |
Output is correct |
18 |
Correct |
231 ms |
19616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
2 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
5 ms |
724 KB |
Output is correct |
5 |
Correct |
4 ms |
700 KB |
Output is correct |
6 |
Correct |
4 ms |
696 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
108 ms |
13944 KB |
Output is correct |
9 |
Correct |
151 ms |
7920 KB |
Output is correct |
10 |
Correct |
384 ms |
20200 KB |
Output is correct |
11 |
Correct |
232 ms |
20656 KB |
Output is correct |
12 |
Correct |
230 ms |
19212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
111 ms |
13868 KB |
Output is correct |
15 |
Correct |
31 ms |
1876 KB |
Output is correct |
16 |
Correct |
459 ms |
20196 KB |
Output is correct |
17 |
Correct |
229 ms |
19544 KB |
Output is correct |
18 |
Correct |
230 ms |
19620 KB |
Output is correct |
19 |
Correct |
520 ms |
59164 KB |
Output is correct |
20 |
Correct |
535 ms |
59228 KB |
Output is correct |
21 |
Correct |
535 ms |
59228 KB |
Output is correct |
22 |
Correct |
524 ms |
59228 KB |
Output is correct |
23 |
Correct |
528 ms |
59240 KB |
Output is correct |
24 |
Correct |
517 ms |
59212 KB |
Output is correct |
25 |
Correct |
548 ms |
59232 KB |
Output is correct |
26 |
Correct |
548 ms |
59224 KB |
Output is correct |
27 |
Correct |
534 ms |
59232 KB |
Output is correct |
28 |
Correct |
619 ms |
59228 KB |
Output is correct |
29 |
Correct |
521 ms |
59236 KB |
Output is correct |
30 |
Correct |
556 ms |
59228 KB |
Output is correct |