#include<bits/stdc++.h>
#include "wall.h"
using namespace std;
const int N = 4e6 + 5, INF = 1000000007;
pair<int, int> seg[4 * N];
void build(int k, int l, int r)
{
if(l == r)
{
seg[k] = {0, INF};
return ;
}
int mid = (l + r) / 2;
build(2 * k, l, mid);
build(2 * k + 1, mid + 1, r);
seg[k] = {0, INF};
}
void f(int k, int l, int r, int flag, int val)
{
if(flag == 1)
{
if(val >= seg[k].second)
{
seg[k] = {val, val};
}
if(val >= seg[k].first)
{
seg[k].first = val;
}
}
if(flag == 0)
{
if(val <= seg[k].first)
{
seg[k] = {val, val};
}
if(val <= seg[k].second)
{
seg[k].second = val;
}
}
}
void push(int k, int l, int r)
{
int mid = (l + r) / 2;
if(seg[k].first != 0)
{
f(2 * k, l, mid, 1, seg[k].first);
f(2 * k + 1, mid + 1, r, 1, seg[k].first);
}
if(seg[k].second != INF)
{
f(2 * k, l, mid, 0, seg[k].second);
f(2 * k + 1, mid + 1, r, 0, seg[k].second);
}
seg[k] = {0, INF};
}
void update(int k, int l, int r, int upd_l, int upd_r, int flag, int val)
{
if(upd_r < l or r < upd_l)
{
return ;
}
if(upd_l <= l and r <= upd_r)
{
f(k, l, r, flag, val);
return ;
}
push(k, l, r);
int mid = (l + r) / 2;
update(2 * k, l, mid, upd_l, upd_r, flag, val);
update(2 * k + 1, mid + 1, r, upd_l, upd_r, flag, val);
}
int query(int k, int l, int r, int node)
{
if(l == r)
{
return seg[k].first;
}
int mid = (l + r) / 2;
push(k, l, r);
if(node <= mid)
return query(2 * k, l, mid, node);
else
return query(2 * k + 1, mid + 1, r, node);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
build(1, 1, n);
for(int i = 0; i < k; i++)
{
update(1, 1, n, left[i] + 1, right[i] + 1, 2 - op[i], height[i]);
}
for(int i = 1; i <= n; i++)
{
finalHeight[i - 1] = query(1, 1, n, i);
}
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
7 ms |
672 KB |
Output is correct |
5 |
Correct |
5 ms |
716 KB |
Output is correct |
6 |
Correct |
5 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
135 ms |
8056 KB |
Output is correct |
3 |
Correct |
162 ms |
4116 KB |
Output is correct |
4 |
Correct |
457 ms |
13040 KB |
Output is correct |
5 |
Correct |
238 ms |
16744 KB |
Output is correct |
6 |
Correct |
235 ms |
13740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
716 KB |
Output is correct |
5 |
Correct |
5 ms |
812 KB |
Output is correct |
6 |
Correct |
5 ms |
800 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
126 ms |
9652 KB |
Output is correct |
9 |
Correct |
167 ms |
4824 KB |
Output is correct |
10 |
Correct |
477 ms |
13088 KB |
Output is correct |
11 |
Correct |
245 ms |
14432 KB |
Output is correct |
12 |
Correct |
227 ms |
12784 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
139 ms |
9236 KB |
Output is correct |
15 |
Correct |
31 ms |
1480 KB |
Output is correct |
16 |
Correct |
546 ms |
14268 KB |
Output is correct |
17 |
Correct |
225 ms |
14572 KB |
Output is correct |
18 |
Correct |
242 ms |
11624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
9 ms |
680 KB |
Output is correct |
5 |
Correct |
4 ms |
668 KB |
Output is correct |
6 |
Correct |
5 ms |
716 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
135 ms |
9148 KB |
Output is correct |
9 |
Correct |
173 ms |
5700 KB |
Output is correct |
10 |
Correct |
458 ms |
14380 KB |
Output is correct |
11 |
Correct |
243 ms |
12932 KB |
Output is correct |
12 |
Correct |
224 ms |
13380 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
136 ms |
9184 KB |
Output is correct |
15 |
Correct |
30 ms |
1476 KB |
Output is correct |
16 |
Correct |
551 ms |
13560 KB |
Output is correct |
17 |
Correct |
235 ms |
13136 KB |
Output is correct |
18 |
Correct |
249 ms |
11636 KB |
Output is correct |
19 |
Correct |
696 ms |
62428 KB |
Output is correct |
20 |
Correct |
700 ms |
58780 KB |
Output is correct |
21 |
Correct |
771 ms |
61696 KB |
Output is correct |
22 |
Correct |
788 ms |
57456 KB |
Output is correct |
23 |
Correct |
704 ms |
57268 KB |
Output is correct |
24 |
Correct |
722 ms |
59308 KB |
Output is correct |
25 |
Correct |
699 ms |
57336 KB |
Output is correct |
26 |
Correct |
709 ms |
60500 KB |
Output is correct |
27 |
Correct |
721 ms |
59904 KB |
Output is correct |
28 |
Correct |
732 ms |
60340 KB |
Output is correct |
29 |
Correct |
725 ms |
59916 KB |
Output is correct |
30 |
Correct |
731 ms |
60760 KB |
Output is correct |