#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif
const int INF = (int) 1e9;
struct segment_tree {
int n;
vector<int> add, rmv, s;
segment_tree() {};
segment_tree(int n): n(n) {
add.resize(4 << __lg(n), -INF);
rmv.resize(4 << __lg(n), INF);
s.resize(4 << __lg(n));
};
void apply(int id, int x, int y) {
s[id] = max(s[id], x);
s[id] = min(s[id], y);
if (y < add[id]) {
add[id] = rmv[id] = y;
} else if (x > rmv[id]) {
add[id] = rmv[id] = x;
} else {
add[id] = max(add[id], x);
rmv[id] = min(rmv[id], y);
}
}
void push(int id) {
if (add[id] != -INF || rmv[id] != INF) {
apply(id << 1, add[id], rmv[id]);
apply(id << 1 | 1, add[id], rmv[id]);
add[id] = -INF;
rmv[id] = INF;
}
}
void upd(int id, int l, int r, int u, int v, int x, int y) {
if (u <= l && r <= v) {
apply(id, x, y);
return;
}
push(id);
int mid = l + r >> 1;
if (u <= mid) {
upd(id << 1, l, mid, u, v, x, y);
}
if (mid < v) {
upd(id << 1 | 1, mid + 1, r, u, v, x, y);
}
}
void upd(int l, int r, int x, int y) {
upd(1, 0, n - 1, l, r, x, y);
}
int get(int i) {
int id = 1, l = 0, r = n - 1;
while (l < r) {
int mid = l + r >> 1;
push(id);
id <<= 1;
if (i <= mid) {
r = mid;
} else {
l = mid + 1;
id |= 1;
}
}
return s[id];
}
};
#ifdef ngu
const int N = (int) 1e6 + 5;
#define left phan
#define right minh
int n, k;
int op[N], left[N], right[N], height[N], finalHeight[N];
#endif
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
segment_tree st(n);
for (int i = 0; i < k; ++i) {
st.upd(left[i], right[i], op[i] == 1 ? height[i] : -INF, op[i] == 2 ? height[i] : INF);
}
for (int i = 0; i < n; ++i) {
finalHeight[i] = st.get(i);
}
}
#ifdef ngu
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef ngu
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
#endif
cin >> n >> k;
for (int i = 0; i < k; ++i) {
cin >> op[i] >> left[i] >> right[i] >> height[i];
}
buildWall(n, k, op, left, right, height, finalHeight);
for (int i = 0; i < n; ++i) {
cout << finalHeight[i] << " ";
}
}
#endif
Compilation message
wall.cpp: In member function 'void segment_tree::upd(int, int, int, int, int, int, int)':
wall.cpp:55:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
wall.cpp: In member function 'int segment_tree::get(int)':
wall.cpp:71:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
432 KB |
Output is correct |
2 |
Correct |
2 ms |
568 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
6 ms |
956 KB |
Output is correct |
5 |
Correct |
4 ms |
860 KB |
Output is correct |
6 |
Correct |
4 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
500 KB |
Output is correct |
2 |
Correct |
114 ms |
13920 KB |
Output is correct |
3 |
Correct |
143 ms |
6824 KB |
Output is correct |
4 |
Correct |
486 ms |
21208 KB |
Output is correct |
5 |
Correct |
200 ms |
21764 KB |
Output is correct |
6 |
Correct |
185 ms |
20216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
4 ms |
892 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
0 ms |
440 KB |
Output is correct |
8 |
Correct |
111 ms |
13820 KB |
Output is correct |
9 |
Correct |
135 ms |
8056 KB |
Output is correct |
10 |
Correct |
398 ms |
21160 KB |
Output is correct |
11 |
Correct |
191 ms |
21840 KB |
Output is correct |
12 |
Correct |
183 ms |
20340 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
119 ms |
13968 KB |
Output is correct |
15 |
Correct |
28 ms |
2136 KB |
Output is correct |
16 |
Correct |
494 ms |
21216 KB |
Output is correct |
17 |
Correct |
191 ms |
20584 KB |
Output is correct |
18 |
Correct |
186 ms |
20584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
496 KB |
Output is correct |
4 |
Correct |
6 ms |
860 KB |
Output is correct |
5 |
Correct |
4 ms |
892 KB |
Output is correct |
6 |
Correct |
4 ms |
856 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
119 ms |
13908 KB |
Output is correct |
9 |
Correct |
139 ms |
8408 KB |
Output is correct |
10 |
Correct |
390 ms |
21220 KB |
Output is correct |
11 |
Correct |
198 ms |
21840 KB |
Output is correct |
12 |
Correct |
178 ms |
20308 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
114 ms |
13828 KB |
Output is correct |
15 |
Correct |
27 ms |
2284 KB |
Output is correct |
16 |
Correct |
495 ms |
21156 KB |
Output is correct |
17 |
Correct |
192 ms |
20748 KB |
Output is correct |
18 |
Correct |
196 ms |
20872 KB |
Output is correct |
19 |
Correct |
551 ms |
75672 KB |
Output is correct |
20 |
Correct |
562 ms |
75604 KB |
Output is correct |
21 |
Correct |
551 ms |
75736 KB |
Output is correct |
22 |
Correct |
663 ms |
75640 KB |
Output is correct |
23 |
Correct |
546 ms |
75716 KB |
Output is correct |
24 |
Correct |
554 ms |
75600 KB |
Output is correct |
25 |
Correct |
570 ms |
75644 KB |
Output is correct |
26 |
Correct |
558 ms |
75744 KB |
Output is correct |
27 |
Correct |
571 ms |
75604 KB |
Output is correct |
28 |
Correct |
543 ms |
75628 KB |
Output is correct |
29 |
Correct |
558 ms |
75776 KB |
Output is correct |
30 |
Correct |
569 ms |
75604 KB |
Output is correct |