# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593614 | Vanilla | Wall (IOI14_wall) | C++17 | 0 ms | 0 KiB |
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 <vector>
#include "wall.h"
using namespace std;
const int maxn = 2e6 + 1;
struct node {
int mn = 1e6;
int mx = 0;
void propagate (node &p1, node &p2) {
p1.merge(mn, mx);
p2.merge(mn, mx);
mn = 1e6, mx = 0;
}
void merge (const int &mn2, const int &mx2) {
mn = min(mn, mn2);
mx = max(min(mn2, mx), mx2);
}
void operator= (const pair <int, int> &x) {
mn = x.first, mx = x.second;
}
};
node sgt [4 * maxn];
void upd (int x, int l, int r, int il, int ir, int h, int op) {
if (l > ir || r < il) return;
if (il <= l && r <= ir) {
if (op == 1) sgt[x].merge(1e6, h);
else sgt[x].merge(h, 0);
return;
}
sgt[x].propagate(sgt[x * 2], sgt[x * 2 + 1]);
int mid = (l + r) / 2;
upd(x * 2, l, mid, il, ir, h, op);
upd(x * 2 + 1, mid + 1, r, il, ir, h, op);
}
void get (int x, int l, int r, int a[]){
if (l > r) return;
if (l == r) {
a[l] = sgt[x].mx;
return;
}
sgt[x].propagate(sgt[x * 2], sgt[x * 2 + 1]);
int mid = (l + r) / 2;
get(x * 2, l, mid, a);
get(x * 2 + 1, mid + 1, r, a);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for (int i = 0; i < k; i++){
upd(1, 0, n-1, left[i], right[i], height[i], op[i]);
}
get(1, 0, n-1, finalHeight);
return;
}