이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <wall.h>
using namespace std;
const int MAX_N = 1e5;
struct Segm {
int x, L, R;
};
vector<Segm>segm;
void push(int pos, int l, int r) {
if(l==r) {
if(segm[pos].L > segm[pos].x) segm[pos].x = segm[pos].L;
if(segm[pos].R < segm[pos].x) segm[pos].x = segm[pos].R;
segm[pos].L = 0, segm[pos].R = MAX_N;
return;
}
if(segm[pos].L) {
segm[2*pos+1].L = max(segm[2*pos+1].L, segm[pos].L);
segm[2*pos+2].L = max(segm[2*pos+2].L, segm[pos].L);
segm[pos].L = 0;
}
if(segm[pos].R != MAX_N) {
segm[2*pos+1].R = min(segm[2*pos+1].R, segm[pos].R);
segm[2*pos+2].R = min(segm[2*pos+2].R, segm[pos].R);
segm[pos].R = MAX_N;
}
}
void update(int pos, int l, int r, int L, int R, int val, int type) {
if(r < L or l > R) return;
if(l != r) {
int m = (l+r)/2;
push(2*pos+1, l, m);
push(2*pos+2, m+1, r);
}
push(pos, l, r);
if(l >= L && r <= R) {
if(type == 1) segm[pos].L = val;
else segm[pos].R = val;
return;
}
int mid = (l+r)/2;
update(2*pos+1, l, mid, L, R, val, type);
update(2*pos+2, mid+1, r, L, R, val, type);
}
int query(int pos, int l, int r, int x) {
if(l != r) {
int m = (l+r)/2;
push(2*pos+1, l, m);
push(2*pos+2, m+1, r);
}
push(pos, l, r);
if(l == r) return segm[pos].x;
int mid = (l+r)/2;
if(mid >= x) return query(2*pos+1, l, mid, x);
else return query(2*pos+2, mid+1, r, x);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
Segm tmp;
tmp.x = 0;
tmp.L = 0;
tmp.R = MAX_N;
segm.assign(8*n, tmp);
for(int i=0; i<k; ++i) {
update(1, 1, n, left[i]+1, right[i]+1, height[i], op[i]);
}
for(int i=1; i<=n; ++i) {
finalHeight[i-1] = query(1, 1, n, i);
}
}
/*signed main() {
int op[6] = {1, 2, 2, 1, 1, 2}, left[6] = {1, 4, 3, 0, 2, 6}, right[6] = {8, 9, 6, 5, 2, 7}, height[6] = {4, 1, 5, 3, 5, 0};
int finalHeight[6];
buildWall(10, 6, op, left, right, height, finalHeight);
}*/
# | 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... |