#include "wall.h"
#include <algorithm>
#define MAXN 2000000
#define MAXP 4200000
#define INF 100000
int atLeast[MAXP], atMost[MAXP], ans[MAXN], left, right, h, tip;
inline void unu(int p, int h) {
atLeast[p] = std::max(atLeast[p], h);
atMost[p] = std::max(atMost[p], atLeast[p]);
}
inline void doi(int p, int h) {
atMost[p] = std::min(atMost[p], h);
atLeast[p] = std::min(atLeast[p], atMost[p]);
}
inline void propag(int p, int st, int dr) {
unu(st, atLeast[p]);
doi(st, atMost[p]);
unu(dr, atLeast[p]);
doi(dr, atMost[p]);
atLeast[p] = 0;
atMost[p] = INF;
}
void update(int p, int st, int dr) {
if (left <= st && dr <= right) {
if (tip == 1)
unu(p, h);
else
doi(p, h);
} else {
propag(p, 2 * p, 2 * p + 1);
int m = (st + dr) / 2;
if (left <= m) update(2 * p, st, m);
if (m < right) update(2 * p + 1, m + 1, dr);
}
}
void dfs(int p, int st, int dr) {
if (st == dr)
ans[st] = atLeast[p];
else {
propag(p, 2 * p, 2 * p + 1);
int m = (st + dr) / 2;
dfs(2 * p, st, m);
dfs(2 * p + 1, m + 1, dr);
}
}
void buildWall(int n, int k, int op[], int left0[], int right0[], int height[], int finalHeight[]) {
for (int i = 0; i < k; i++) {
tip = op[i];
left = left0[i];
right = right0[i];
h = height[i];
update(1, 0, n - 1);
}
dfs(1, 0, n - 1);
for (int i = 0; i < n; i++)
finalHeight[i] = ans[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
9 ms |
896 KB |
Output is correct |
5 |
Correct |
7 ms |
880 KB |
Output is correct |
6 |
Correct |
8 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
189 ms |
13912 KB |
Output is correct |
3 |
Correct |
197 ms |
8204 KB |
Output is correct |
4 |
Correct |
595 ms |
20856 KB |
Output is correct |
5 |
Correct |
336 ms |
21948 KB |
Output is correct |
6 |
Correct |
299 ms |
20236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
7 ms |
896 KB |
Output is correct |
6 |
Correct |
6 ms |
896 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
185 ms |
13944 KB |
Output is correct |
9 |
Correct |
222 ms |
8056 KB |
Output is correct |
10 |
Correct |
575 ms |
20856 KB |
Output is correct |
11 |
Correct |
432 ms |
21880 KB |
Output is correct |
12 |
Correct |
308 ms |
20408 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
182 ms |
13996 KB |
Output is correct |
15 |
Correct |
31 ms |
2040 KB |
Output is correct |
16 |
Correct |
496 ms |
21112 KB |
Output is correct |
17 |
Correct |
328 ms |
20468 KB |
Output is correct |
18 |
Correct |
280 ms |
20476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
356 KB |
Output is correct |
4 |
Correct |
8 ms |
896 KB |
Output is correct |
5 |
Correct |
7 ms |
896 KB |
Output is correct |
6 |
Correct |
10 ms |
896 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
171 ms |
13944 KB |
Output is correct |
9 |
Correct |
160 ms |
8060 KB |
Output is correct |
10 |
Correct |
542 ms |
20760 KB |
Output is correct |
11 |
Correct |
313 ms |
21880 KB |
Output is correct |
12 |
Correct |
318 ms |
20216 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
224 ms |
13944 KB |
Output is correct |
15 |
Correct |
33 ms |
2040 KB |
Output is correct |
16 |
Correct |
494 ms |
21016 KB |
Output is correct |
17 |
Correct |
303 ms |
20416 KB |
Output is correct |
18 |
Correct |
287 ms |
20464 KB |
Output is correct |
19 |
Correct |
677 ms |
77136 KB |
Output is correct |
20 |
Correct |
673 ms |
74696 KB |
Output is correct |
21 |
Correct |
757 ms |
77124 KB |
Output is correct |
22 |
Correct |
761 ms |
74752 KB |
Output is correct |
23 |
Correct |
657 ms |
74616 KB |
Output is correct |
24 |
Correct |
818 ms |
74640 KB |
Output is correct |
25 |
Correct |
810 ms |
74576 KB |
Output is correct |
26 |
Correct |
761 ms |
77128 KB |
Output is correct |
27 |
Correct |
715 ms |
77092 KB |
Output is correct |
28 |
Correct |
766 ms |
74688 KB |
Output is correct |
29 |
Correct |
663 ms |
74692 KB |
Output is correct |
30 |
Correct |
768 ms |
74672 KB |
Output is correct |