#include "wall.h"
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
constexpr int maxn = 2e6 + 5, bit = 32 - __builtin_clz(maxn), siz = 1 << bit, max_val = 1e9;
const array<int, 2> defa = {0, max_val};
array<int, 2> segtree[siz * 2] = { 0 };
void comp(array<int, 2> &lower, const array<int,2>&over)
{
if (over[1] < lower[0])
{
lower[0] = lower[1] = over[1];
} else if (over[0] > lower[1])
{
lower[0] = lower[1] = over[0];
} else if (lower[0] <= over[0] && over[1] <= lower[1]) {
lower = over;
} else {
lower[0] = max(lower[0], over[0]);
lower[1] = min(lower[1], over[1]);
}
}
void propogate(int p)
{
comp(segtree[p * 2], segtree[p]);
comp(segtree[p * 2 + 1], segtree[p]);
segtree[p] = defa;
}
void update(int pos, int l, int r, int gl, int gr, array<int, 2> p)
{
if (gl > r || l > gr) return ;
// Inside
if (gl <= l && r <= gr)
{
comp(segtree[pos], p);
return ;
}
propogate(pos);
int mid = (l + r) >> 1;
update(pos * 2, l, mid, gl, gr, p);
update(pos * 2 + 1, mid + 1, r, gl, gr, p);
}
int output[maxn] = { 0 };
void fnd_answers(int pos, int l, int r, int gl, int gr)
{
if (l > gr || gl > r) return ;
if (segtree[pos][0] == segtree[pos][1])
{
for (int i = l; i <= r; i++) output[i] = segtree[pos][0];
// cout << "finished: " <<l << " " << r << "\n";
return ;
}
propogate(pos);
int mid = (l + r) >> 1;
fnd_answers(pos * 2, l, mid, gl, gr);
fnd_answers(pos * 2 + 1, mid + 1, r, gl, gr);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for (int i = 0; i < siz; i++) segtree[i][1] = max_val;
array<int, 2> p;
for (int i = 0; i < k; i++)
{
// Min
if (op[i] == 1) p[0] = height[i], p[1] = max_val;
// Max
else p[0] = 0, p[1] = height[i];
update(1, 0, siz - 1, left[i], right[i], p);
// cout << i << "\n";
// for (int i = 1; i < 2 * siz; i++)
// {
// if (__builtin_popcount(i) == 1) cout << "\n";
// cout << segtree[i][0] << " " << segtree[i][1] << "\t";
// }
// cout << endl << endl;
}
fnd_answers(1, 0, siz - 1, 0, n - 1);
for (int i = 0; i < n; i++) finalHeight[i] = output[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16724 KB |
Output is correct |
2 |
Correct |
10 ms |
16832 KB |
Output is correct |
3 |
Correct |
11 ms |
16724 KB |
Output is correct |
4 |
Correct |
13 ms |
17048 KB |
Output is correct |
5 |
Correct |
12 ms |
17108 KB |
Output is correct |
6 |
Correct |
12 ms |
17064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16724 KB |
Output is correct |
2 |
Correct |
239 ms |
30288 KB |
Output is correct |
3 |
Correct |
217 ms |
24040 KB |
Output is correct |
4 |
Correct |
521 ms |
35848 KB |
Output is correct |
5 |
Correct |
325 ms |
36968 KB |
Output is correct |
6 |
Correct |
293 ms |
35416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
9 ms |
16824 KB |
Output is correct |
3 |
Correct |
8 ms |
16704 KB |
Output is correct |
4 |
Correct |
13 ms |
17056 KB |
Output is correct |
5 |
Correct |
12 ms |
17020 KB |
Output is correct |
6 |
Correct |
12 ms |
17108 KB |
Output is correct |
7 |
Correct |
7 ms |
16724 KB |
Output is correct |
8 |
Correct |
239 ms |
30376 KB |
Output is correct |
9 |
Correct |
203 ms |
24012 KB |
Output is correct |
10 |
Correct |
519 ms |
35980 KB |
Output is correct |
11 |
Correct |
308 ms |
36916 KB |
Output is correct |
12 |
Correct |
295 ms |
35348 KB |
Output is correct |
13 |
Correct |
10 ms |
16624 KB |
Output is correct |
14 |
Correct |
294 ms |
30372 KB |
Output is correct |
15 |
Correct |
39 ms |
18036 KB |
Output is correct |
16 |
Correct |
567 ms |
36120 KB |
Output is correct |
17 |
Correct |
315 ms |
35596 KB |
Output is correct |
18 |
Correct |
309 ms |
35528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16732 KB |
Output is correct |
2 |
Correct |
8 ms |
16852 KB |
Output is correct |
3 |
Correct |
8 ms |
16724 KB |
Output is correct |
4 |
Correct |
15 ms |
17008 KB |
Output is correct |
5 |
Correct |
12 ms |
17104 KB |
Output is correct |
6 |
Correct |
14 ms |
17084 KB |
Output is correct |
7 |
Correct |
8 ms |
16648 KB |
Output is correct |
8 |
Correct |
236 ms |
30272 KB |
Output is correct |
9 |
Correct |
196 ms |
24248 KB |
Output is correct |
10 |
Correct |
521 ms |
35856 KB |
Output is correct |
11 |
Correct |
315 ms |
36920 KB |
Output is correct |
12 |
Correct |
305 ms |
35348 KB |
Output is correct |
13 |
Correct |
7 ms |
16688 KB |
Output is correct |
14 |
Correct |
243 ms |
30400 KB |
Output is correct |
15 |
Correct |
38 ms |
18052 KB |
Output is correct |
16 |
Correct |
562 ms |
36100 KB |
Output is correct |
17 |
Correct |
303 ms |
35492 KB |
Output is correct |
18 |
Correct |
321 ms |
35576 KB |
Output is correct |
19 |
Correct |
631 ms |
72668 KB |
Output is correct |
20 |
Correct |
628 ms |
70132 KB |
Output is correct |
21 |
Correct |
626 ms |
72784 KB |
Output is correct |
22 |
Correct |
635 ms |
70260 KB |
Output is correct |
23 |
Correct |
640 ms |
70072 KB |
Output is correct |
24 |
Correct |
631 ms |
70100 KB |
Output is correct |
25 |
Correct |
623 ms |
70296 KB |
Output is correct |
26 |
Correct |
617 ms |
72704 KB |
Output is correct |
27 |
Correct |
627 ms |
72688 KB |
Output is correct |
28 |
Correct |
629 ms |
70040 KB |
Output is correct |
29 |
Correct |
622 ms |
70088 KB |
Output is correct |
30 |
Correct |
649 ms |
70064 KB |
Output is correct |