This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** * * * * * * * * * * * * * * **\
* *
* Author: Haidara Nassour *
* Coded in: 2021\09\12 HH:MM:SS *
* Lang: C++ *
* *
\** * * * * * * * * * * * * * * **/
#include<bits/stdc++.h>
#include<wall.h>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define FOR(i,n) rep(i,0,n)
using namespace std;
const int maxn=2000200;
int n;
struct node
{
int mintall=0,lazy=0;
} st[maxn*4];
int ul,ur,val;
bool mn=0,mx=0;
int check(int inx)
{
if(st[inx].lazy==0)
return st[inx].mintall;
if(mn)
return min(st[inx].mintall,st[inx].lazy);
return max(st[inx].mintall,st[inx].lazy);
}
void pu(int inx)
{
st[inx].mintall=min(check(inx*2),check(inx*2+1));
}
void pull(int inx,int l,int r)
{
if(st[inx].lazy)
{
if(mn)
st[inx].mintall=min(st[inx].mintall,st[inx].lazy);
else
st[inx].mintall=max(st[inx].mintall,st[inx].lazy);
if(l!=r)
{
if(mn)
{
st[inx*2].lazy=min(st[inx*2].lazy,st[inx].lazy);
st[inx*2+1].lazy=min(st[inx*2+1].lazy,st[inx].lazy);
}
else
{
st[inx*2].lazy=max(st[inx*2].lazy,st[inx].lazy);
st[inx*2+1].lazy=max(st[inx*2+1].lazy,st[inx].lazy);
}
}
}
st[inx].lazy=0;
}
void update(int l=1,int r=n,int inx=1)
{
pull(inx,l,r);
if(ul<=l&&r<=ur)
{
st[inx].lazy=val;
pull(inx,l,r);
return ;
}
if(ul>r||l>ur)
return ;
int mid=l+(r-l)/2;
update(l,mid,inx*2);
update(mid+1,r,inx*2+1);
pu(inx);
}
int query(int pos,int l=1,int r=n,int inx=1)
{
pull(inx,l,r);
if(l==r)
return st[inx].mintall;
int mid=l+(r-l)/2;
if(pos<=mid)
return query(pos,l,mid,inx*2);
return query(pos,mid+1,r,inx*2+1);
}
void buildWall(int sz, int k, int op[], int left[], int right[],int height[], int finalHeight[])
{
n=sz;
FOR(i,k)
{
val=height[i];
left[i]++;
right[i]++;
ul=left[i];
ur=right[i];
mn=mx=0;
if(op[i]>1)
mn=1;
else
mx=1;
update();
}
FOR(i,n)
finalHeight[i]=query(i+1);
}
# | 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... |