이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
const int N = 3e6;
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
if(n <= 100) {
for(int i = 0; i < n; i++)
finalHeight[i] = 0;
for(int i = 0; i < k; i++) {
if(op[i] == 1) {
for(int j = left[i]; j <= right[i]; j++) {
finalHeight[j] = max(finalHeight[j], height[i]);
}
} else if(op[i] == 2) {
for(int j = left[i]; j <= right[i]; j++) {
finalHeight[j] = min(finalHeight[j], height[i]);
}
}
}
return;
}
else {
for(int i = 0; i < n; i++)
finalHeight[i] = 0;
int per = 0;
vector<pair<int, int>> g[n + 1];
for(int i = 0; i < k; i++) {
assert(height[i] >= 0);
}
for(int i = 0; i < k; i++) {
if(op[i] == 2)break;
per = i;
}
multiset<int> q;
for(int j = 0; j <= n; j++)g[j].clear();
q.clear();
for(int i = 0; i <= per; i++) {
assert(op[i] == 1);
g[left[i]].pb(mp(height[i], 1));
g[right[i] + 1].pb(mp(height[i], -1));
}
for(int j = 0; j < n; j++) {
for(auto u : g[j]) {
if(u.s < 0)
q.erase(q.find(u.f));
else
q.insert(u.f);
}
if(q.size()) finalHeight[j] = max(0, *q.rbegin());
}
for(int j = 0; j <= n; j++)g[j].clear();
q.clear();
for(int i = per + 1; i < k; i++) {
assert(op[i] == 2);
g[left[i]].pb(mp(height[i], 1));
g[right[i] + 1].pb(mp(height[i], -1));
}
for(int j = 0; j < n; j++) {
for(auto u : g[j]) {
if(u.s < 0)
q.erase(q.find(u.f));
else
q.insert(u.f);
}
if(q.size())finalHeight[j] = min(finalHeight[j], *q.begin());
}
}
return;
}
/*
int main()
{
int n;
int k;
int i, j;
int status = 0;
status = scanf("%d%d", &n, &k);
assert(status == 2);
int* op = (int*)calloc(sizeof(int), k);
int* left = (int*)calloc(sizeof(int), k);
int* right = (int*)calloc(sizeof(int), k);
int* height = (int*)calloc(sizeof(int), k);
int* finalHeight = (int*)calloc(sizeof(int), n);
for (i = 0; i < k; i++){
status = scanf("%d%d%d%d", &op[i], &left[i], &right[i], &height[i]);
assert(status == 4);
}
buildWall(n, k, op, left, right, height, finalHeight);
for (j = 0; j < n; j++)
printf("%d\n", finalHeight[j]);
return 0;
}
/*
10 3
1 3 4 91220
1 5 9 48623
2 3 5 39412
*/
컴파일 시 표준 에러 (stderr) 메시지
wall.cpp:111:1: warning: "/*" within comment [-Wcomment]
111 | /*
|| # | 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... |