#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define sp << ' ' <<
#define nl << '\n'
#include "wall.h"
const int INF = 1e18;
struct SegmentTree{
using T = array<int, 2>;
vector<T> a;
int sz = 1;
T ID = {0, INF};
SegmentTree(int n){
while(sz < n) sz += sz;
a.assign(2*sz, ID);
}
void apply(T &x, T &y){
y[0] = max(y[0], x[0]);
y[1] = max(y[1], x[0]);
y[0] = min(y[0], x[1]);
y[1] = min(y[1], x[1]);
}
void push(int x){
if(a[x] == ID) return;
if(x+1<sz){
apply(a[x], a[2*x+1]);
apply(a[x], a[2*x+2]);
a[x] = ID;
}
}
void update(int l, int r, T v, int x, int lx, int rx){
push(x);
if(r<=lx or rx<=l) return;
if(l<=lx and rx<=r) return apply(v, a[x]);
int mx = (lx+rx)/2;
update(l, r, v, 2*x+1, lx, mx);
update(l, r, v, 2*x+2, mx, rx);
}
void update(int l, int r, int low, int high){
T v = {low, high};
update(l, r+1, v, 0, 0, sz);
}
void build(vector<int> &ans, int n, int x, int lx, int rx){
push(x);
if(rx-lx==1){
// cout << a[x][0] nl;
if(lx<n) ans[lx] = a[x][0];
return;
}
int mx = (lx+rx)/2;
build(ans, n, 2*x+1, lx, mx);
build(ans, n, 2*x+2, mx, rx);
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
SegmentTree st(n);
for(int i=0; i<k; ++i){
// cout << op[i] sp left[i] sp right[i] sp height[i] nl;
if(op[i]==1) st.update(left[i], right[i], height[i], INF);
else st.update(left[i], right[i], 0, height[i]);
}
vector<int> ans(n);
st.build(ans, n, 0, 0, st.sz);
for(int i=0; i<n; ++i) finalHeight[i] = ans[i];
}
Compilation message
wall.cpp:8:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
8 | const int INF = 1e18;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
10 ms |
716 KB |
Output is correct |
5 |
Correct |
6 ms |
692 KB |
Output is correct |
6 |
Correct |
8 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
163 ms |
13888 KB |
Output is correct |
3 |
Correct |
253 ms |
7896 KB |
Output is correct |
4 |
Correct |
709 ms |
20488 KB |
Output is correct |
5 |
Correct |
379 ms |
21108 KB |
Output is correct |
6 |
Correct |
386 ms |
19524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
8 ms |
716 KB |
Output is correct |
5 |
Correct |
6 ms |
716 KB |
Output is correct |
6 |
Correct |
6 ms |
800 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
161 ms |
13836 KB |
Output is correct |
9 |
Correct |
269 ms |
7896 KB |
Output is correct |
10 |
Correct |
741 ms |
20508 KB |
Output is correct |
11 |
Correct |
399 ms |
21104 KB |
Output is correct |
12 |
Correct |
371 ms |
19512 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
177 ms |
13908 KB |
Output is correct |
15 |
Correct |
63 ms |
1868 KB |
Output is correct |
16 |
Correct |
776 ms |
20676 KB |
Output is correct |
17 |
Correct |
393 ms |
20036 KB |
Output is correct |
18 |
Correct |
386 ms |
19908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
8 ms |
716 KB |
Output is correct |
5 |
Correct |
8 ms |
716 KB |
Output is correct |
6 |
Correct |
8 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
172 ms |
13844 KB |
Output is correct |
9 |
Correct |
269 ms |
7900 KB |
Output is correct |
10 |
Correct |
751 ms |
20556 KB |
Output is correct |
11 |
Correct |
377 ms |
21024 KB |
Output is correct |
12 |
Correct |
359 ms |
19540 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
170 ms |
13828 KB |
Output is correct |
15 |
Correct |
44 ms |
1964 KB |
Output is correct |
16 |
Correct |
776 ms |
20560 KB |
Output is correct |
17 |
Correct |
383 ms |
19980 KB |
Output is correct |
18 |
Correct |
393 ms |
19872 KB |
Output is correct |
19 |
Correct |
970 ms |
67036 KB |
Output is correct |
20 |
Correct |
950 ms |
67012 KB |
Output is correct |
21 |
Correct |
970 ms |
66972 KB |
Output is correct |
22 |
Correct |
954 ms |
67112 KB |
Output is correct |
23 |
Correct |
967 ms |
67008 KB |
Output is correct |
24 |
Correct |
951 ms |
67240 KB |
Output is correct |
25 |
Correct |
937 ms |
67076 KB |
Output is correct |
26 |
Correct |
938 ms |
67012 KB |
Output is correct |
27 |
Correct |
956 ms |
67152 KB |
Output is correct |
28 |
Correct |
943 ms |
67008 KB |
Output is correct |
29 |
Correct |
942 ms |
67012 KB |
Output is correct |
30 |
Correct |
959 ms |
67016 KB |
Output is correct |