This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "wall.h"
#include<algorithm>
using namespace std;
#define SZ 2097152
int Res[SZ], N;
struct SegTree{
int B, E;
}IT[SZ*2+2];
void spread(int node){
IT[node * 2].B = min(max(IT[node * 2].B, IT[node].B), IT[node].E);
IT[node * 2 + 1].B = min(max(IT[node * 2 + 1].B, IT[node].B), IT[node].E);
IT[node * 2].E = min(max(IT[node * 2].E, IT[node].B), IT[node].E);
IT[node * 2 + 1].E = min(max(IT[node * 2 + 1].E, IT[node].B), IT[node].E);
}
void UDT(int node){
IT[node].B = min(IT[node * 2].B, IT[node * 2 + 1].B);
IT[node].E = max(IT[node * 2].E, IT[node * 2 + 1].E);
}
void Ins(int node, int b, int e, int s, int l, int h, int ck){
if (b == s && e == l){
if (ck == 1){
IT[node].B = max(IT[node].B, h);
IT[node].E = max(IT[node].E, h);
}
else{
IT[node].B = min(IT[node].B, h);
IT[node].E = min(IT[node].E, h);
}
return;
}
spread(node);
int m = (b + e) >> 1;
if (s <= m)Ins(node * 2, b, m, s, min(m, l), h, ck);
if (l > m)Ins(node * 2 + 1, m + 1, e, max(m + 1, s), l, h, ck);
UDT(node);
}
void Do(int node, int b, int e){
if (b >= N)return;
if (b == e){
Res[b] = IT[node].B;
return;
}
spread(node);
int m = (b + e) >> 1;
Do(node * 2, b, m);
Do(node * 2 + 1, m + 1, e);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
int i;
N = n;
for (i = 0; i < k; i++){
Ins(1, 0, SZ - 1, left[i], right[i], height[i], op[i]);
}
Do(1, 0, SZ-1);
for (i = 0; i < n; i++)finalHeight[i] = Res[i];
}
# | 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... |