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<bits/stdc++.h>
#include"wall.h"
#define FOR(i,n) for(int i=0;i<n;i++)
using namespace std;
const int maxn=200200;
int n;
const int inf=1<<29;
struct node
{
int mx=inf,mn=0,lazy=-1;
} st[maxn*4+2];
bool add=0;
int ul,ur,val;
void pull(int inx,int l,int r)
{
if(st[inx].lazy==-1)
return ;
if(add)
{
st[inx].mn=max(st[inx].lazy,st[inx].mn);
st[inx].mx=max(st[inx].mn,st[inx].mx);
if(l!=r)
{
st[inx*2].lazy=max(st[inx].lazy,st[inx*2].lazy);
st[inx*2+1].lazy=max(st[inx].lazy,st[inx*2+1].lazy);
}
}
else
{
st[inx].mx=min(st[inx].mx,st[inx].lazy);
st[inx].mn=min(st[inx].mn,st[inx].mx);
if(l!=r)
{
st[inx*2].lazy=min(st[inx].lazy,st[inx*2].lazy);
st[inx*2+1].lazy=min(st[inx].lazy,st[inx*2+1].lazy);
}
}
st[inx].lazy=-1;
}
int check(int inx,int type)
{
int mintall=st[inx].mn,maxtall=st[inx].mx;
if(st[inx].lazy!=-1)
{
if(add)
{
mintall=max(st[inx].lazy,st[inx].mn);
maxtall=max(st[inx].mn,st[inx].mx);
}
else
{
maxtall=min(st[inx].mx,st[inx].lazy);
mintall=min(st[inx].mn,st[inx].mx);
}
}
if(type==1)
return mintall;
return maxtall;
}
void pu(int inx)
{
/// 1-> min
/// 2-> max
st[inx].mn=min(check(inx*2,1),check(inx*2+1,1));
st[inx].mx=max(check(inx*2,2),check(inx*2+1,2));
}
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(l>ur||ul>r)
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)
{
if(st[inx].mn==st[inx].mx)
return st[inx].mn;
return -500;
}
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];
ul=left[i]+1;
ur=right[i]+1;
if(op[i]==1)
add=1;
else
add=0;
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... |