이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "wall.h"
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = 2e6 + 5;
pair <int, int> st[4 * N];
int ans[N];
int op[N];
int l[N];
int r[N];
int h[N];
int n,k;
void dolazy(int id)
{
for (int i = (id << 1); i <= (id << 1 | 1); i++)
{
st[i].fi = max(st[i].fi, st[id].fi);
st[i].se = min(st[i].se, st[id].se);
if (st[i].fi > st[i].se)
{
if (st[i].fi == st[id].fi)
st[i].se = st[i].fi;
else
st[i].fi = st[i].se;
}
}
}
void update(int id, int l, int r, int u, int v, int val, int op)
{
if (l > v || r < u)
return;
if (l >= u && r <= v)
{
if (op == 1)
{
st[id].fi = max(st[id].fi, val);
if (st[id].fi > st[id].se)
st[id].se = st[id].fi;
} else {
st[id].se = min(st[id].se, val);
if (st[id].fi > st[id].se)
st[id].fi = st[id].se;
}
return;
}
int mid = (l + r) >> 1;
dolazy(id);
update(id << 1, l, mid, u, v, val, op);
update(id << 1 | 1, mid + 1, r, u, v, val, op);
st[id].fi = min(st[id << 1].fi, st[id << 1 | 1].fi);
st[id].se = max(st[id << 1].se, st[id << 1 | 1].se);
}
int getval(int id, int l, int r, int pos)
{
if (l > pos || r < pos)
return -1;
if (l == r)
return st[id].fi;
int mid = (l + r) >> 1;
dolazy(id);
int lnode = getval(id << 1, l, mid, pos);
int rnode = getval(id << 1 | 1, mid + 1, r, pos);
return max(lnode, rnode);
}
void buildWall(int n, int k, int op[], int l[], int r[], int h[], int ans[])
{
for (int i = 0; i < k; i++)
update(1, 1, n, l[i] + 1, r[i] + 1, h[i], op[i]);
for (int i = 1; i <= n; i++)
ans[i - 1] = getval(1, 1, n, i);
/**for (int i = 0; i < n; i++)
cerr << ans[i] << endl;*/
}
# | 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... |