답안 #972830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972830 2024-05-01T08:41:11 Z sleepntsheep 벽 (IOI14_wall) C
0 / 100
176 ms 17252 KB
#include "wall.h"

#define MAX_N 2000002

int chmax[MAX_N<<2], chmin[MAX_N<<2], min[MAX_N<<2], max[MAX_N<<2];

void pull(int v)
{
    min[v]=min[v<<1|(min[v<<1]>min[v<<1|1])];
    max[v]=max[v<<1|(max[v<<1]<max[v<<1|1])];
}

void do_chmax(int v,int l,int r,int k)
{
    if(chmin[v]!=-1&&chmin[v]<=k){chmin[v]=-1,chmax[v]=k;return;}
    chmax[v]=k;return;
}

void do_chmin(int v,int l,int r,int k)
{
    if(chmax[v]!=-1&&chmax[v]>=k){chmax[v]=-1,chmin[v]=k;return;}
    chmin[v]=k;return;
}

void push(int v,int l,int r)
{
    if(chmin[v]!=-1)
    {
        if(chmin[v]<min[v])min[v]=max[v]=chmin[v];
        else if(chmin[v]<max[v])max[v]=chmin[v];
        if(l!=r) do_chmin(v<<1,l,l+(r-l)/2,chmin[v]),do_chmin(v<<1|1,l+(r-l)/2+1,r,chmin[v]);
        chmin[v]=-1;
    }
    if(chmax[v]!=-1)
    {
        if(chmax[v]>=max[v])min[v]=max[v]=chmax[v];
        else if(chmax[v]>=min[v])min[v]=chmax[v];
        if(l!=r) do_chmax(v<<1|1,l+(r-l)/2+1,r,chmax[v]),do_chmax(v<<1,l,l+(r-l)/2,chmax[v]);
        chmax[v]=-1;
    }
}

void do_do(int v,int l,int r,int x,int y,int k,void(*op)(int,int,int,int))
{
    push(v,l,r);
    if(r<x||y<l)return;
    if(x<=l&&r<=y){op(v,l,r,k);push(v,l,r);return ;}
    do_do(v<<1,l,l+(r-l)/2,x,y,k,op),do_do(v<<1|1,l+(r-l)/2+1,r,x,y,k,op);
    pull(v);
}

void build(int v,int l,int r)
{
    chmin[v]=chmax[v]=-1;
    if(l==r)min[v]=max[v]=0;
    else build(v<<1,l,l+(r-l)/2),build(v<<1|1,l+(r-l)/2+1,r),pull(v);
}

void ans(int v,int l,int r,int *o)
{
    push(v,l,r);
    if(l==r){o[l]=min[v];return;}
    ans(v<<1,l,l+(r-l)/2,o),ans(v<<1|1,l+(r-l)/2+1,r,o);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    build(1,0,n-1);
    for(int i=0;i<k;++i)
        if(op[i]==2)do_do(1,0,n-1,left[i],right[i],height[i],do_chmin);
        else do_do(1,0,n-1,left[i],right[i],height[i],do_chmax);
    ans(1,0,n-1,finalHeight);
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Incorrect 2 ms 6644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6568 KB Output is correct
2 Correct 107 ms 17252 KB Output is correct
3 Incorrect 176 ms 13652 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 2 ms 6496 KB Output is correct
3 Incorrect 2 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 2 ms 6588 KB Output is correct
3 Incorrect 2 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -