이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
struct segtree {
struct Node {
int min;
int max;
};
vector<Node> t;
int no_min = INT_MAX;
int no_max = INT_MIN;
int sz;
void init(int n){
sz = 1;
while(sz < n)sz <<= 1;
t.assign(sz*2, {0, 0});
}
void modify(int Max, int Min, int node){
t[node].max = min(Max, max(Min, t[node].max));
t[node].min = min(Max, max(Min, t[node].min));
}
void push(int node, int len){
if(len == 1 || t[node].min == no_min && t[node].max == no_max){
t[node] = {no_min, no_max};
return;
}
modify(t[node].max, t[node].min, node*2);
modify(t[node].max, t[node].min, node*2+1);
t[node] = {no_min, no_max};
}
void add(int l, int r, int L, int R, int node, int Max, int Min){
if(L >= r || R <= l)return;
push(node, R-L);
if(L >= l && R <= r){
modify(Max, Min, node);
return;
}
int mid = (L+R)/2;
add(l, r, L, mid, node*2, Max, Min);
add(l, r, mid, R, node*2+1,Max,Min);
}
void add(int l, int r, int Max, int Min){
add(l, r, 0, sz, 1, Max, Min);
}
int get(int i, int L, int R, int node){
if(R-L == 1){
return t[node].min;
}
push(node, R-L);
int mid = (L+R)/2;
if(i < mid)return get(i, L, mid, node*2);
else return get(i, mid, R, node*2+1);
}int get(int i){
int ans = max(get(i, 0, sz, 1), 0);
return ans;
}
};
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
segtree seg;
seg.init(n);
for(int i=0;i<k;i++){
if(op[i] == 1){
// add
seg.add(left[i], right[i]+1, height[i], seg.no_min);
}else {
// remove
seg.add(left[i], right[i]+1, seg.no_max, height[i]);
}
}
for(int i=0;i<n;i++){
finalHeight[i] = seg.get(i);
}
return;
}
/*
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
*/
컴파일 시 표준 에러 (stderr) 메시지
wall.cpp: In member function 'void segtree::push(int, int)':
wall.cpp:23:40: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
23 | if(len == 1 || t[node].min == no_min && t[node].max == no_max){
# | 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... |