이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<algorithm>
#include<cstdio>
#include "wall.h"
using namespace std;
const int maxn=2000000+5;
const int INF=(1<<30);
int Max[maxn*6],Min[maxn*6];
inline void add(int id,int val)
{
if(Max[id]==-1) Min[id]=max(Min[id],val);
else if(val>=Max[id]) Min[id]=val,Max[id]=-1;
else if(val>=Min[id]) Min[id]=val;
}
inline void remove(int id,int val)
{
if(Max[id]==-1) Min[id]=min(Min[id],val);
else if(val<=Min[id]) Min[id]=val,Max[id]=-1;
else if(val<=Max[id]) Max[id]=val;
}
inline void push(int id)
{
if(Max[id]==-1)
{
Max[id*2]=Max[id*2+1]=-1;
Min[id*2]=Min[id*2+1]=Min[id];
Max[id]=INF,Min[id]=0;
return;
}
if(Min[id]!=0) { add(id*2,Min[id]); add(id*2+1,Min[id]);}
if(Max[id]!=INF) { remove(id*2,Max[id]); remove(id*2+1,Max[id]); }
Max[id]=INF,Min[id]=0;
}
void modify(int id,int L,int R,int qL,int qR,int qtype,int qhei)
{
if(qL<= L && R <=qR)
{
if(qtype==1) add(id,qhei);
else remove(id,qhei);
return;
}
int M=L+(R-L)/2;
push(id);
if(qL<=M) modify(id*2,L,M,qL,qR,qtype,qhei);
if(qR> M) modify(id*2+1,M+1,R,qL,qR,qtype,qhei);
}
void buildans(int id,int L,int R,int* ans)
{
if(L==R) {ans[L]=Min[id];return;}
int M=L+(R-L)/2;
push(id);
buildans(id*2,L,M,ans);
buildans(id*2+1,M+1,R,ans);
}
void buildWall(int n,int k,int op[],int left[],int right[],int height[],int finalHeight[])
{
for(int i=0;i<n*3;i++) Max[i]=INF,Min[i]=0;
for(int i=0;i<k;i++) modify(1,0,n-1,left[i],right[i],op[i],height[i]);
buildans(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... |