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"
#define MAX_N 4000002
int lo(int a,int b){return a>b?b:a;}
int hi(int a,int b){return a<b?b:a;}
int min[MAX_N<<2], max[MAX_N<<2];
void apply(int v,int kl,int kh)
{
min[v]=hi(kh,lo(min[v],kl));
max[v]=hi(kh,lo(max[v],kl));
}
void push(int v,int l,int r)
{
apply(v<<1,min[v],max[v]);
apply(v<<1|1,min[v],max[v]);
if(l!=r) min[v]=1e9,max[v]=-1e9;
}
void upd(int v,int l,int r,int x,int y,int kl,int kh)
{
push(v,l,r);
if(r<x||y<l)return;
if(x<=l&&r<=y){apply(v,kl,kh);return;}
upd(v<<1,l,l+(r-l)/2,x,y,kl,kh),upd(v<<1|1,l+(r-l)/2+1,r,x,y,kl,kh);
}
void build(int v,int l,int r)
{
if(l==r)min[v]=max[v]=0;
else build(v<<1,l,l+(r-l)/2),build(v<<1|1,l+(r-l)/2+1,r);
}
void ans(int v,int l,int r,int *o)
{
push(v,l,r);
if(l==r){o[l]=min[v];return;}
ans(v<<1,l,l+(r-l)/2,o),ans(v<<1|1,l+(r-l)/2+1,r,o);
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
build(1,0,n-1);
for(int i=0;i<k;++i) upd(1,0,n-1,left[i],right[i],op[i]==1?1e9:height[i],op[i]==2?-1e9:height[i]);
ans(1,0,n-1,finalHeight);
}
# | 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... |