# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
593572 | 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 <bits/stdc++.h>
#include "wall.h"
using namespace std;
const int maxn = 2e6 + 2;
int rs [maxn];
struct node {
int mn = 1e9;
int mx = 0;
void propagate (node &p1, node &p2) {
p1.merge(mn, mx);
p2.merge(mn, mx);
mn = 1e9, mx = 0;
}
void merge (int mn2, 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;
}
} 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(1e9, 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){
if (l > r) return;
if (l == r) {
rs[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);
get(x * 2 + 1, mid + 1, r);
}
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);
for (int i = 0; i < n; i++) finalHeight[i] = rs[i];
return;
}