이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define L(i) i*2+1
#define R(i) i*2+2
using namespace std;
typedef pair<int, int> pii;
pii update(int i, int l, int r, int a, int b, pii op, pii* tree, pii* lazy){
if(lazy[i].first != -1){
tree[i].first = min(max(tree[i].first, lazy[i].first), lazy[i].second);
tree[i].second = max(min(tree[i].second, lazy[i].second), lazy[i].first);
if(l != r) {
lazy[L(i)] = lazy[R(i)] = {tree[i].first, tree[i].second};
}
lazy[i] = {-1, -1};
}
if(l > b || r < a) return tree[i];
if(a <= l && r <= b){
if(op.first == 1){
tree[i].first = max(tree[i].first, op.second);
if(tree[i].first > tree[i].second){
tree[i].second = tree[i].first;
}
} else {
tree[i].second = min(tree[i].second, op.second);
if(tree[i].first > tree[i].second){
tree[i].first = tree[i].second;
}
}
if(l != r) lazy[L(i)] = lazy[R(i)] = tree[i];
}
if(l != r){
int mid = (l+r)/2;
pii left = update(L(i), l, mid, a, b, op, tree, lazy), right = update(R(i), mid+1, r, a, b, op, tree, lazy);
tree[i] = {min(left.first, right.first), max(left.second, right.second)};
}
return tree[i];
}
void get(int i, int l, int r, pii* tree, pii* lazy, int finalHeight[]){
if(lazy[i].first != -1){
tree[i].first = min(max(tree[i].first, lazy[i].first), lazy[i].second);
tree[i].second = max(min(tree[i].second, lazy[i].second), lazy[i].first);
if(l != r) {
lazy[L(i)] = lazy[R(i)] = {tree[i].first, tree[i].second};
}
lazy[i] = {-1, -1};
}
if(l == r){
finalHeight[l] = tree[i].first;
} else {
int mid = (l+r)/2;
get(L(i), l, mid, tree, lazy, finalHeight);
get(R(i), mid+1, r, tree, lazy, finalHeight);
}
}
void buildWall(int n, int k, int op[], int left[], int right[],int height[], int finalHeight[]){
pii *tree = new pii[4 * n + 10], *lazy = new pii[4 * n + 10];
for(int i = 0;i < 4*n+10;i++) {
lazy[i] = {-1, -1};
tree[i] = {0, 0};
}
for(int i = 0;i < k;i++){
update(0, 0, n-1, left[i], right[i], {op[i], height[i]}, tree, lazy);
}
get(0, 0, n-1, tree, lazy, finalHeight);
delete[] tree;
delete[] lazy;
}
컴파일 시 표준 에러 (stderr) 메시지
wall.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
1 | #pragma GCC optimization ("unroll-loops")
|
# | 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... |