# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420350 | iulia13 | Wall (IOI14_wall) | C++14 | 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 <iostream>
#include "wall.h"
using namespace std;
const int N = 2e6 + 5;
const int INF = 2e9;
struct Node{
int minim, maxim;
} seg[4 * N];
void op1(int nod, int val)
{
seg[nod].minim = min(seg[nod].minim, val);
seg[nod].maxim = min(val, seg[nod].maxim);
}
void op2(int nod, int val)
{
seg[nod].maxim = max(seg[nod].maxim, val);
seg[nod].minim = max(val, seg[nod].minim);
}
void push(int nod)
{
int ls = 2 * nod, rs = ls + 1;
op1(ls, seg[nod].minim);
op1(rs, seg[nod].minim);
op2(ls, seg[nod].maxim);
op2(rs, seg[nod].maxim);
}
void update(int nod, int l, int r, int ql, int qr, int val, int tip)
{
if (l > r || l > qr || r < ql)
return;
if (ql <= l && r <= qr)
{
if (tip == 2)
op1(nod, val);
else
op2(nod, val);
return;
}
int mid = (l + r) / 2, ls = 2 * nod, rs = ls + 1;
push(nod);
seg[nod].maxim = 0;
seg[nod].minim = INF;
update(ls, l, mid, ql, qr, val, tip);
update(rs, mid + 1, r, ql, qr, val, tip);
}
int aa[N];
void query(int nod, int l, int r){
if(l == r)
{
aa[l] = min(seg[nod].maxim, seg[nod].minim);
return;
}
int mid = (l + r) / 2, ls = 2 * nod, rs = ls + 1;
push(nod);
seg[nod].maxim = 0;
seg[nod].minim = INF;
query(ls, l, mid);
query(rs, mid + 1, r);
}
void buildwall(int n, int k, int op[], int lft[], int rgt[], int height[], int ans[])
{
int i;
for (int h = 0; h < k; h++)
{
lft[h]++;
rgt[h]++;
update(1, 1, n, lft[h], rgt[h], height[h], op[h]);
}
query(1, 1, n);
for (i = 0; i < n; i++)
ans[i] = aa[i + 1];
}