#include "wall.h" /// DO NOT CHANGE THIS LINE
#include <bits/stdc++.h>
using namespace std;
#define task ""
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};
const int INF = 1e9 + 7;
const int MAX = 1234567;
int n, h[MAX];
pair<int, int> st[MAX << 2];
void build(int id, int l, int r) {
st[id] = {0, INF};
if (l == r) {
// maximize(st[id].second, h[l]);
// maximize(st[id].first, h[l]);
return;
}
int mid = l + r >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
}
void push(int id, int u, int d) {
minimize(st[id].second, d);
maximize(st[id].second, u);
maximize(st[id].first, u);
minimize(st[id].first, d);
}
void push(int id) {
push(id << 1, st[id].first, st[id].second);
push(id << 1 | 1, st[id].first, st[id].second);
st[id] = {0, INF};
}
void update(int id, int l, int r, int u, int v, int newH, int t) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
if (t == 0) {
maximize(st[id].second, newH);
maximize(st[id].first, newH);
} else {
minimize(st[id].second, newH);
minimize(st[id].first, newH);
}
return;
}
int mid = l + r >> 1; push(id);
update(id << 1, l, mid, u, v, newH, t);
update(id << 1 | 1, mid + 1, r, u, v, newH, t);
}
int get(int pos) {
int id = 1, l = 1, r = n;
while (l < r) {
int mid = l + r >> 1; push(id);
if (pos <= mid) id = id << 1, r = mid;
else id = id << 1 | 1, l = mid + 1;
}
return min(st[id].first, st[id].second);
}
void prepare(int subtask, const vector<int> &height) {
n = height.size();
for (int i = 1; i <= n; ++i) {
h[i] = height[i - 1];
}
build(1, 1, n);
}
void build_up(int l, int r, int t) { ++l; ++r;
update(1, 1, n, l, r, t, 0);
}
void take_down(int l, int r, int t) { ++l; ++r;
update(1, 1, n, l, r, t, 1);
}
int get_height(int i) { ++i;
return get(i);
}
void buildWall(int N, int K, int op[], int left[], int right[], int height[], int finalHeight[]) {
n = N;
build(1, 1, n);
for (int i = 0; i < K; ++i) {
update(1, 1, n, left[i] + 1, right[i] + 1, height[i], op[i]);
}
for (int i = 0; i < n; ++i) {
finalHeight[i] = get(i + 1);
}
}
Compilation message
wall.cpp: In function 'void build(int, int, int)':
wall.cpp:31:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int mid = l + r >> 1;
| ~~^~~
wall.cpp: In function 'void update(int, int, int, int, int, int, int)':
wall.cpp:61:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int mid = l + r >> 1; push(id);
| ~~^~~
wall.cpp: In function 'int get(int)':
wall.cpp:69:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | int mid = l + r >> 1; push(id);
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |