이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* user: ppavic
* fname: Patrik
* lname: Pavić
* task: wall
* score: 100.0
* date: 2019-06-25 09:50:17.292891
*/
#include "wall.h"
#include <cstdio>
#include <algorithm>
using namespace std;
const int OFF = (1 << 21);
const int INF = 0x3f3f3f3f;
int mx[2 * OFF ], mi[2 * OFF];
void spoji(int j,int i){
int olmi = mi[i];
mx[i] = min(mx[i], mx[j]);
mi[i] = max(mi[i], mi[j]);
//if(i == OFF + 1) printf("nov nov %d %d\n", mi[i], mx[i]);
if(mi[i] > mx[i]){
//if(i == OFF + 1) printf("tu sam %d %d\n", mi[i], mi[j]);
if(olmi < mi[j])
mx[i] = mi[i];
else
mi[i] = mx[i];
}
}
void prop(int i){
if(i < OFF){
spoji(i, 2 * i);
spoji(i, 2 * i + 1);
mx[i] = INF, mi[i] = 0;
}
}
void update(int i,int a,int b,int lo,int hi){
prop(i);
if(lo <= a && b <= hi){
//printf("prije %d %d , dodaj %d %d\n", mi[i], mx[i], mi[0], mx[0]);
spoji(0, i);
//printf("I : %d A : %d B : %d => %d %d\n", i, a, b, mi[i], mx[i]);
prop(i);
return;
}
if(a > hi || b < lo) return;
update(2 * i, a, (a + b) / 2, lo, hi);
update(2 * i + 1, (a + b) / 2 + 1, b, lo, hi);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
for(int i = 0;i < k;i++){
mi[0] = 0, mx[0] = INF;
if(op[i] == 2) mx[0] = height[i];
else mi[0] = height[i];
update(1, 0, OFF - 1, left[i], right[i]);
//printf(" trenutno : ");
//for(int i = 0;i < n;i++) printf("{%d %d} ", mi[OFF + i], mx[OFF + i]);
//printf("\n\n");
}
for(int i = 1;i < OFF;i++) prop(i);
for(int i = 0;i < n;i++) finalHeight[i] = mi[OFF + i];
return;
}
# | 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... |