#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1 << 11;
constexpr int INF = 1e9;
struct SegTree {
vector<int> segmin;
vector<int> segmax;
vector<int> seg;
int n;
SegTree(int n) : segmin(2 * N, -1), segmax(2 * N, -1), seg(2 * N), n(n) {
fill_n(segmin.begin() + n, n, 0);
fill_n(segmax.begin(), n, INF);
}
void update(int l, int r, int h, int op) {
#ifdef DEBUG
printf("%s [%d, %d): %d\n", op == 1 ? "ADD" : "REMOVE", l, r, h);
print();
#endif
l += n;
r += n;
while (r > l) {
if (l & 1) {
push(l);
if (op == 1)
segmin[l] = h;
else
segmax[l] = h;
l++;
}
if (r & 1) {
r--;
push(r);
if (op == 1)
segmin[r] = h;
else
segmax[r] = h;
}
l /= 2;
r /= 2;
}
}
int query(int i) {
i += n;
return seg[i];
}
void propagate() {
for (int i = 1; i <= 2 * n; ++i) {
push(i);
}
}
void push(int u) {
if (u >= n) {
// leaf
if (segmin[u] != -1) {
seg[u] = max(segmin[u], seg[u]);
segmin[u] = -1;
}
if (segmax[u] != -1) {
seg[u] = min(segmax[u], seg[u]);
segmax[u] = -1;
}
return;
}
if (segmin[u * 2] != -1 || segmax[u * 2] != -1) {
push(u * 2);
}
if (segmin[u * 2 + 1] != -1 || segmax[u * 2 + 1] != -1) {
push(u * 2 + 1);
}
if (segmin[u] != -1) {
segmin[u * 2] = segmin[u];
segmin[u * 2 + 1] = segmin[u];
/*
if (segmin[u * 2] != -1)
segmin[u * 2] = max(segmin[u * 2], segmin[u]);
else
segmin[u * 2] = segmin[u];
if (segmin[u * 2 + 1] != -1)
segmin[u * 2 + 1] = max(segmin[u * 2 + 1], segmin[u]);
else
segmin[u * 2 + 1] = segmin[u];
*/
segmin[u] = -1;
}
if (segmax[u] != -1) {
/*
if (segmax[u * 2] != -1)
segmax[u * 2] = min(segmax[u * 2], segmax[u]);
else
segmax[u * 2] = segmax[u];
if (segmax[u * 2 + 1] != -1)
segmax[u * 2 + 1] = min(segmax[u * 2 + 1], segmax[u]);
else
segmax[u * 2 + 1] = segmax[u];
*/
segmax[u * 2] = segmax[u];
segmax[u * 2 + 1] = segmax[u];
segmax[u] = -1;
}
}
void print() {
propagate();
printf("--TREE--\n");
int stop = 1;
int layer = 1;
for (int i = 1; i <= 2 * n; ++i) {
printf("[%d, %d] ", segmin[i], segmax[i]);
if (i == stop) {
printf("\n");
stop += (layer *= 2);
}
}
printf("\n--LEAF--\n");
for (int i = 0; i < n; ++i) {
printf("%d ", query(i));
}
printf("\n\n\n");
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[],
int finalHeight[]) {
SegTree tr(n);
for (int i = 0; i < k; ++i) {
tr.update(left[i], right[i] + 1, height[i], op[i]);
}
tr.propagate();
for (int i = 0; i < n; ++i) {
finalHeight[i] = tr.query(i);
}
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
80 ms |
13972 KB |
Output is correct |
3 |
Runtime error |
44 ms |
11100 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
572 KB |
Output is correct |
3 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |