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<algorithm>
struct tree
{
int min;
int max;
} t[4444444];
void upd(int i,int s,int e,int l,int r,int op,int height)
{
if(l<s)l=s;
if(r>e)r=e;
if(l>r)return;
if(l==s&&r==e)
{
if(op==1)
{
t[i].min = std::max(t[i].min,height);
t[i].max = std::max(t[i].max,height);
}
if(op==2)
{
t[i].min = std::min(t[i].min,height);
t[i].max = std::min(t[i].max,height);
}
return;
}
t[i*2].max=std::max(t[i*2].max,t[i].min);
t[i*2].max=std::min(t[i*2].max,t[i].max);
t[i*2].min=std::max(t[i*2].min,t[i].min);
t[i*2].min=std::min(t[i*2].min,t[i].max);
t[i*2+1].max=std::max(t[i*2+1].max,t[i].min);
t[i*2+1].max=std::min(t[i*2+1].max,t[i].max);
t[i*2+1].min=std::max(t[i*2+1].min,t[i].min);
t[i*2+1].min=std::min(t[i*2+1].min,t[i].max);
t[i].min=0;
t[i].max=100000;
upd(i*2,s,(s+e)/2,l,r,op,height);
upd(i*2+1,(s+e)/2+1,e,l,r,op,height);
}
void get(int i,int s,int e,int finalHeight[])
{
if(s==e)
{
finalHeight[s]=t[i].min;
return;
}
t[i*2].max=std::max(t[i*2].max,t[i].min);
t[i*2].max=std::min(t[i*2].max,t[i].max);
t[i*2].min=std::max(t[i*2].min,t[i].min);
t[i*2].min=std::min(t[i*2].min,t[i].max);
t[i*2+1].max=std::max(t[i*2+1].max,t[i].min);
t[i*2+1].max=std::min(t[i*2+1].max,t[i].max);
t[i*2+1].min=std::max(t[i*2+1].min,t[i].min);
t[i*2+1].min=std::min(t[i*2+1].min,t[i].max);
get(i*2,s,(s+e)/2,finalHeight);
get(i*2+1,(s+e)/2+1,e,finalHeight);
}
void buildWall(int n,int k,int op[],int left[],int right[],int height[],int finalHeight[])
{
int i;
for(i=0;i<k;i++)upd(1,0,n-1,left[i],right[i],op[i],height[i]);
get(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... |