#include "wall.h";
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int inf = 1e9;
const int N = 2e6 + 10;
int n, k;
struct LazyTree {
pii lz[4 * N];
void init() {
for (int i = 0; i < 4 * N; i++) lz[i] = pii(inf, inf);
}
void push(int i, int b, int e) {
if (lz[i] == pii(inf, inf)) return;
if (b < e) {
if (lz[i * 2].first == inf) lz[i * 2] = lz[i];
else if (lz[i].second == 2) lz[i * 2] = min(lz[i * 2], lz[i]);
else lz[i * 2] = max(lz[i * 2], lz[i]);
if (lz[i * 2 + 1].first == inf) lz[i * 2 + 1] = lz[i];
else if (lz[i].second == 2) lz[i * 2 + 1] = min(lz[i * 2 + 1], lz[i]);
else lz[i * 2 + 1] = max(lz[i * 2 + 1], lz[i]);
lz[i] = pii(inf, inf);
}
}
void update(int i, int b, int e, int l, int r, int v, int op) {
push(i, b, e);
if (r < b || e < l) return;
if (l <= b && e <= r) {
lz[i] = pii(v, op);
push(i, b, e);
return;
}
int mid = (b + e) / 2;
update(i * 2, b, mid, l, r, v, op);
update(i * 2 + 1, mid + 1, e, l, r, v, op);
}
void update(int l, int r, int v, int op) {
update(1, 0, n - 1, l, r, v, op);
}
int query(int i, int b, int e, int x) {
push(i, b, e);
if (b == e) return lz[i].first;
int mid = (b + e) / 2;
if (x <= mid) return query(i * 2, b, mid, x);
else return query(i * 2 + 1, mid + 1, e, x);
}
int query(int x) {
return query(1, 0, n - 1, x);
}
}
st;
void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[]) {
n = N, k = K;
st.init();
for (int i = 0; i < k; i++) {
st.update(left[i], right[i], height[i], op[i]);
//cout << i + 1 << " -> ";
//for (int i = 0; i < n; i++) cout << st.query(i) << " "; cout << "\n";
}
for (int i = 0; i < n; i++) {
finalHeight[i] = st.query(i);
}
}
Compilation message
wall.cpp:1:18: warning: extra tokens at end of #include directive
1 | #include "wall.h";
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
63056 KB |
Output is correct |
2 |
Incorrect |
10 ms |
63056 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
63056 KB |
Output is correct |
2 |
Incorrect |
89 ms |
70892 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
63056 KB |
Output is correct |
2 |
Incorrect |
10 ms |
63224 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
63056 KB |
Output is correct |
2 |
Incorrect |
11 ms |
63056 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |