#include "wall.h"
#include <cassert>
bool ckmin(auto& a, const auto& b) {return b<a?a=b,1:0;}
bool ckmax(auto& a, const auto& b) {return b>a?a=b,1:0;}
const int MX = 1 << 22; // ~4m
const int INF = 0x3f3f3f3f;
int flr[MX], cel[MX];
void updf(int n, int v) {ckmax(flr[n], v); ckmax(cel[n], v);}
void updc(int n, int v) {ckmin(flr[n], v); ckmin(cel[n], v);}
void down(int n)
{
updf(n<<1, flr[n]);
updf(n<<1|1, flr[n]);
updc(n<<1, cel[n]);
updc(n<<1|1, cel[n]);
flr[n]=-INF;
cel[n]=INF;
}
void updf(int n, int l, int r, int ql, int qr, int v)
{
if(ql <= l&&r <= qr) updf(n, v);
else
{
int m=l+(r-l)/2;
down(n);
if(ql<m) updf(n<<1, l, m, ql, qr, v);
if(m<qr) updf(n<<1|1, m, r, ql, qr, v);
}
}
void updc(int n, int l, int r, int ql, int qr, int v)
{
if(ql <= l&&r <= qr) updc(n, v);
else
{
int m=l+(r-l)/2;
down(n);
if(ql<m) updc(n<<1, l, m, ql, qr, v);
if(m<qr) updc(n<<1|1, m, r, ql, qr, v);
}
}
void fill(int n, int l, int r, int *f)
{
if(r-l>1)
{
int m=l+(r-l)/2;
down(n);
fill(n<<1, l, m, f);
fill(n<<1|1, m, r, f);
}
else
{
f[l]=flr[n];
assert(flr[n]==cel[n]);
}
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[])
{
for(int i=0;i<k;++i)
{
if(op[i]==1) updf(1, 0, n, left[i], right[i]+1, height[i]);
if(op[i]==2) updc(1, 0, n, left[i], right[i]+1, height[i]);
}
fill(1, 0, n, finalHeight);
}
Compilation message
wall.cpp:4:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
4 | bool ckmin(auto& a, const auto& b) {return b<a?a=b,1:0;}
| ^~~~
wall.cpp:4:27: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
4 | bool ckmin(auto& a, const auto& b) {return b<a?a=b,1:0;}
| ^~~~
wall.cpp:5:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
5 | bool ckmax(auto& a, const auto& b) {return b>a?a=b,1:0;}
| ^~~~
wall.cpp:5:27: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
5 | bool ckmax(auto& a, const auto& b) {return b>a?a=b,1:0;}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
8 ms |
748 KB |
Output is correct |
5 |
Correct |
8 ms |
732 KB |
Output is correct |
6 |
Correct |
7 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
191 ms |
11584 KB |
Output is correct |
3 |
Correct |
232 ms |
7612 KB |
Output is correct |
4 |
Correct |
726 ms |
14140 KB |
Output is correct |
5 |
Correct |
432 ms |
14628 KB |
Output is correct |
6 |
Correct |
337 ms |
14744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
10 ms |
756 KB |
Output is correct |
5 |
Correct |
5 ms |
756 KB |
Output is correct |
6 |
Correct |
5 ms |
812 KB |
Output is correct |
7 |
Correct |
1 ms |
284 KB |
Output is correct |
8 |
Correct |
181 ms |
11588 KB |
Output is correct |
9 |
Correct |
222 ms |
7680 KB |
Output is correct |
10 |
Correct |
626 ms |
14116 KB |
Output is correct |
11 |
Correct |
400 ms |
14588 KB |
Output is correct |
12 |
Correct |
334 ms |
14620 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
198 ms |
11524 KB |
Output is correct |
15 |
Correct |
43 ms |
1952 KB |
Output is correct |
16 |
Correct |
769 ms |
14436 KB |
Output is correct |
17 |
Correct |
352 ms |
14360 KB |
Output is correct |
18 |
Correct |
377 ms |
14404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
420 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
9 ms |
716 KB |
Output is correct |
5 |
Correct |
5 ms |
716 KB |
Output is correct |
6 |
Correct |
8 ms |
700 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
218 ms |
11552 KB |
Output is correct |
9 |
Correct |
255 ms |
7560 KB |
Output is correct |
10 |
Correct |
601 ms |
14116 KB |
Output is correct |
11 |
Correct |
364 ms |
14624 KB |
Output is correct |
12 |
Correct |
344 ms |
14620 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
208 ms |
11580 KB |
Output is correct |
15 |
Correct |
41 ms |
1960 KB |
Output is correct |
16 |
Correct |
720 ms |
14364 KB |
Output is correct |
17 |
Correct |
368 ms |
14368 KB |
Output is correct |
18 |
Correct |
335 ms |
14428 KB |
Output is correct |
19 |
Correct |
854 ms |
62480 KB |
Output is correct |
20 |
Correct |
885 ms |
62928 KB |
Output is correct |
21 |
Correct |
866 ms |
69412 KB |
Output is correct |
22 |
Correct |
891 ms |
62844 KB |
Output is correct |
23 |
Correct |
883 ms |
62904 KB |
Output is correct |
24 |
Correct |
838 ms |
62920 KB |
Output is correct |
25 |
Correct |
865 ms |
62828 KB |
Output is correct |
26 |
Correct |
851 ms |
69468 KB |
Output is correct |
27 |
Correct |
850 ms |
69472 KB |
Output is correct |
28 |
Correct |
907 ms |
62772 KB |
Output is correct |
29 |
Correct |
880 ms |
62792 KB |
Output is correct |
30 |
Correct |
861 ms |
62840 KB |
Output is correct |