이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
struct segtree {
vector<int> st, t, o;
int sz;
segtree(int n) {
sz = n;
while (__builtin_popcount(sz) ^ 1) sz++;
st.resize(sz << 1), o.resize(sz << 1, -1);
}
void change(int v, int val, int op) {
if (o[v] == -1 && v < sz) st[v] = val, o[v] = op;
else if (op == 1) {
if (st[v] <= val) {
st[v] = val;
o[v] = 1;
}
} else if (op == 2) {
if (st[v] >= val) {
st[v] = val;
o[v] = 2;
}
}
}
void push(int v) {
change(v << 1, st[v], o[v]);
change(v << 1 | 1, st[v], o[v]);
o[v] = -1;
}
void upd(int v, int l, int r, int ql, int qr, int op, int h) {
if (l > qr || r < ql) return;
if (l >= ql && r <= qr) {
change(v, h, op);
return;
}
if (o[v] != -1) push(v);
int m = l + r >> 1;
upd(v << 1, l, m, ql, qr, op, h);
upd(v << 1 | 1, m + 1, r, ql, qr, op, h);
}
void pushdown(int v) {
if (v >= sz) return;
if (o[v] != -1) push(v);
pushdown(v << 1);
pushdown(v << 1 | 1);
}
void upd(int l, int r, int op, int h) {
upd(1, 0, sz - 1, l, r, op, h);
}
int get(int i) {
return st[i + sz];
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int hieght[], int finalhieght[]) {
segtree st(n);
for (int i = 0; i < k; i++)
st.upd(left[i], right[i], op[i], hieght[i]);
st.pushdown(1);
for (int i = 0; i < n; i++) finalhieght[i] = st.get(i);
}
컴파일 시 표준 에러 (stderr) 메시지
wall.cpp: In member function 'void segtree::upd(int, int, int, int, int, int, int)':
wall.cpp:39:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int m = l + r >> 1;
| ~~^~~
# | 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... |