# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
309901 | thecodingwizard | 벽 (IOI14_wall) | C++11 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "wall.h"
struct node {
int small = 0, large = 1e9+20;
int lazy = 0;
void upd(int op, int h) {
if (op == 1) {
// min
small = max(small, h);
large = max(large, h);
} else {
// max
small = min(small, h);
large = min(large, h);
}
lazy = 1;
}
};
node st[8000000];
void down(int p, int i, int j) {
if (st[p].lazy == 0) return;
if (i == j) return;
st[p*2].lazy = 1; st[p*2].small = st[p].small; st[p*2].large = st[p].large;
st[p*2+1].lazy = 1; st[p*2+1].small = st[p].small; st[p*2+1].large = st[p].large;
st[p].lazy = 0;
}
void upd(int p, int i, int j, int l, int r, int op, int h) {
down(p, i, j);
if (i > r || j < l) return;
if (l <= i && j <= r) {
st[p].upd(op, h);
return;
}
upd(p*2, i, (i+j)/2, l, r, op, h);
upd(p*2+1, (i+j)/2+1, j, l, r, op, h);
}
int qry(int p, int i, int j, int x) {
down(p, i, j);
if (i == j && i == x) {
return st[p].small;
}
if ((i+j)/2 >= x) return qry(p*2, i, (i+j)/2, x);
return qry(p*2+1, (i+j)/2+1, j, x);
}
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], op[i], height[i]);
}
for (int i = 0; i < n; i++) {
finalHeight[i] = qry(1, 0, n-1, i);
}
}