제출 #472613

#제출 시각아이디문제언어결과실행 시간메모리
472613HaidaraWall (IOI14_wall)C++17
0 / 100
220 ms8060 KiB
/** * * * * * * * * * * * * * * **\
 *                               *
 *    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;
int check(int inx)
{
    if(st[inx].lazy<0)
    {
        if(st[inx].mintall>(-1)*st[inx].lazy)
            return st[inx].lazy*(-1);
    }
    else if(st[inx].lazy>0)
    {
        if(st[inx].mintall<st[inx].lazy)
            return st[inx].lazy;
    }
    return st[inx].mintall;
}
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<0)
    {
        if(st[inx].mintall>(-1)*st[inx].lazy)
            st[inx].mintall=st[inx].lazy*(-1);
    }
    else if(st[inx].lazy>0)
    {
        if(st[inx].mintall<st[inx].lazy)
            st[inx].mintall=st[inx].lazy;
    }
    if(l!=r&&st[inx].lazy!=0)
    {
        st[inx*2].lazy=st[inx].lazy;
        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];
        if(op[i]>1)
            val*=-1;
        update();
    }
    FOR(i,n)
    finalHeight[i]=query(i+1);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...