이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/** * * * * * * * * * * * * * * **\
* *
* 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=200200;
int n;
struct node
{
int mx=0,mn=0,lazy=-1,tall=0;
} st[maxn*4];
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].tall=max(st[inx].lazy,st[inx].tall);
}
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);
}
else
st[inx].tall=min(st[inx].tall,st[inx].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].tall)
return st[inx].mn;
if(st[inx].mx<st[inx].tall)
return st[inx].mx;
return st[inx].tall;
}
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... |