This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "wall.h"
using namespace std;
#define N 500005
int lim[4 * N], seg[4 * N], h[N];
void clear(int nd){
seg[nd * 2] = max(seg[nd * 2], min(lim[nd * 2], seg[nd]));
seg[nd * 2 + 1] = max(seg[nd * 2 + 1], min(lim[nd * 2 + 1], seg[nd]));
lim[nd * 2] = min(lim[nd * 2], lim[nd]);
lim[nd * 2 + 1] = min(lim[nd * 2 + 1], lim[nd]);
}
void update(int nd, int L, int R, int l, int r, int h, int t){
// cout << nd << ' '<< L << ' ' << R<< endl;
if (r < L || R < l) return;
if (t == 1) h = min(h, lim[nd]);
if (l <= L && R <= r){
if (t == 1) seg[nd] = max(seg[nd], h);
else lim[nd] = min(h, lim[nd]);
return;
}
clear(nd);
update(nd * 2, L, (L + R) / 2, l, r, h, t);
update(nd * 2 + 1, (L + R) / 2 + 1, R, l, r, h, t);
}
void end(int nd, int l, int r){
if (l == r){
h[l] = seg[nd];
return;
}
clear(nd);
end(nd * 2, l, (l + r) / 2);
end(nd * 2 + 1, (l + r) / 2 + 1, r);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for (int i = 0;i <= 4 * n;i++) lim[i] = 2e9;
for (int i = k - 1;i >= 0;i--) update(1, 0, n - 1, left[i], right[i], height[i], op[i]);
end(1, 0, n - 1);
for (int i = 0;i < n;i++) finalHeight[i] = h[i];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |