# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
472689 | Haidara | Wall (IOI14_wall) | C++17 | 0 ms | 0 KiB |
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>
#include"wall.h"
#define FOR(i,n) for(int i=0;i<n;i++)
using namespace std;
const int maxn=2000001;
int n;
const int inf=0x7fffffff;
struct node
{
int mx=0x7fffffff,mn=0;
} st[maxn*4];
bool add=0;
int ul,ur,val;
void update(int l=1,int r=n,int inx=1)
{
if(ul<=l&&r<=ur)
{
if(add)
{
st[inx].mn=max(st[inx].mn,val);
st[inx].mx=max(st[inx].mn,st[inx].mx);
}
else
{
st[inx].mx=min(st[inx].mx,val);
st[inx].mn=min(st[inx].mn,st[inx].mx);
}
if(l!=r)
{
st[inx*2].mn=max(st[inx*2].mn,st[inx].mn);
st[inx*2].mx=min(st[inx*2].mx,st[inx].mx);
st[inx*2+1].mn=max(st[inx*2+1].mn,st[inx].mn);
st[inx*2+1].mx=min(st[inx*2+1].mx,st[inx].mx);
st[inx].mn=0;
st[inx].mx=inf;
}
return ;
}
if(l>ur||ul>r)
return ;
st[inx*2].mn=max(st[inx*2].mn,st[inx].mn);
st[inx*2].mx=min(st[inx*2].mx,st[inx].mx);
st[inx*2+1].mn=max(st[inx*2+1].mn,st[inx].mn);
st[inx*2+1].mx=min(st[inx*2+1].mx,st[inx].mx);
st[inx].mn=0;
st[inx].mx=inf;
int mid=l+(r-l)/2;
update(l,mid,inx*2);
update(mid+1,r,inx*2+1);
}
int query(int pos,int l=1,int r=n,int inx=1)
{
if(l==r)
return st[inx].mn;
int mid=l+(r-l)/2;
st[inx*2].mn=max(st[inx*2].mn,st[inx].mn);
st[inx*2].mx=min(st[inx*2].mx,st[inx].mx);
st[inx*2+1].mn=max(st[inx*2+1].mn,st[inx].mn);
st[inx*2+1].mx=min(st[inx*2+1].mx,st[inx].mx);
st[inx].mn=0;
st[inx].mx=inf;
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);
}