답안 #1099549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099549 2024-10-11T14:59:57 Z vjudge1 벽 (IOI14_wall) C++17
24 / 100
367 ms 31568 KB
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include "wall.h"
using namespace std;
#define ll long long
#define PLL pair<ll, ll>
#define PB push_back
#define F first
#define S second
#define MP make_pair

void build(ll v, ll l, ll r, vector<PLL> &t, vector<PLL> &actu){
    actu[v].F = -1;
    actu[v].S = -1;
    if(l==r){
        t[v] = MP(0ll,0ll);
        return;
    }
    ll m = (l+r)/2;
    build(2*v,l,m,t,actu);
    build(2*v+1,m+1,r,t,actu);
    t[v].F = min(t[2*v].F,t[2*v+1].F);
    t[v].S = max(t[2*v].S,t[2*v+1].S);
}

void propagate(ll v, ll l, ll r, vector<PLL>&t, vector<PLL>&actu){
  //cout<<"propagating: "<<v<<" "<<l<<" "<<r<<endl;
  //cout<<t[v].F<<" "<<t[v].S<<endl;

  //cout<<actu[v].F<<" "<<actu[v].S<<endl;
    if(actu[v].F!=-1){
        if(t[v].S>actu[v].F){
            t[v].S = actu[v].F;
            t[v].F = min(t[v].F,actu[v].F);
            if(l!=r){
                actu[2*v].F = min(actu[v].F,actu[2*v].F);
                if(actu[2*v].F==-1){
                    actu[2*v].F = actu[v].F;
                }
                if(actu[2*v].S>actu[v].F){
                    actu[2*v].S=actu[v].F;
                    actu[2*v].F = actu[v].F;
                }
                actu[2*v+1].F = min(actu[v].F,actu[2*v+1].F);
                if(actu[2*v+1].F==-1){
                    actu[2*v+1].F = actu[v].F;
                }
                if(actu[2*v+1].S>actu[v].F){
                    actu[2*v+1].S=actu[v].F;
                    actu[2*v+1].F = actu[v].F;
                }
            }
            else{
                t[v].F = actu[v].F;
            }
        }
        actu[v].F = -1;
    }
    if(actu[v].S!=-1){
        if(t[v].F<actu[v].S){
            t[v].F = actu[v].S;
            t[v].S = max(t[v].S,actu[v].S);
            if(l!=r){
                actu[2*v].S = max(actu[v].S,actu[2*v].S);
                if(actu[2*v].F<actu[v].S and actu[2*v].F!=-1){
                    actu[2*v].F=actu[v].F;
                    actu[2*v].S = actu[v].S;
                }
                actu[2*v+1].S = max(actu[v].S,actu[2*v+1].S);
                if(actu[2*v+1].F<actu[v].S and actu[2*v+1].F!=-1){
                    actu[2*v+1].F=actu[v].F;
                    actu[2*v+1].S = actu[v].S;
                }
            }
            else{
                t[v].S = actu[v].S;
            }
        }
        actu[v].S = -1;
    }
    //cout<<t[v].F<<" "<<t[v].S<<endl;
}

void adding(ll v, ll l, ll r, ll lx, ll rx, ll h, vector<PLL>&t, vector<PLL>&actu){ 
    if(actu[v].F!=-1 or actu[v].S!=-1){
        propagate(v,l,r,t,actu);
    } 
    if(lx<=l and r<=rx){
        if(actu[v].F<h and actu[v].F !=-1){
            actu[v].S = h;
            actu[v].F = h;
        }
        else{
            actu[v].S = max(actu[v].S,h);
        }
        propagate(v,l,r,t,actu);
        return;
    }
    if(l>rx or r<lx){
        return;
    }
    ll m = (l+r)/2;
    adding(2*v,l,m,lx,rx,h,t,actu);
    adding(2*v+1,m+1,r,lx,rx,h,t,actu);
    t[v].F = min(t[2*v].F,t[2*v+1].F);
    t[v].S = max(t[2*v].S,t[2*v+1].S);
}

void removing (ll v, ll l, ll r, ll lx, ll rx, ll h, vector<PLL>&t, vector<PLL>&actu){  
    if(actu[v].F!=-1 or actu[v].S!=-1){
        propagate(v,l,r,t,actu);
    }
    if(lx<=l and r<=rx){
        //actu[v].F = h;
        if(actu[v].S>h){
            actu[v].S = h;
            actu[v].F = h;
        }
        else if(actu[v].F!=-1){
            actu[v].F = min(actu[v].F,h);
        }
        else{
            actu[v].F = h;
        }
        propagate(v,l,r,t,actu);
        return;
    }
    if(l>rx or r<lx){
        return;
    }
    ll m = (l+r)/2;
    removing(2*v,l,m,lx,rx,h,t,actu);
    removing(2*v+1,m+1,r,lx,rx,h,t,actu);
    t[v].F = min(t[2*v].F,t[2*v+1].F);
    t[v].S = max(t[2*v].S,t[2*v+1].S);
}

void recover(ll v, ll l, ll r, vector<PLL> &t,vector<PLL> &actu, vector<int> &ans){
    //cout<<v<<" "<<l<<" "<<r<<endl;
    if(actu[v].F!=-1 or actu[v].S!=-1){
        propagate(v,l,r,t,actu); 
    }
    if(l==r){
        //cout<<t[v].F<<endl;
        ans[l] = t[v].F;
        return;
    }
    ll m = (l+r)/2;
    recover(2*v,l,m,t,actu,ans);
    recover(2*v+1,m+1,r,t,actu,ans);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    vector<PLL> t(4*n), actu(4*n);
    build(1,0,n-1,t,actu);
    for(ll i=0; i<k; i++){
        //cout<<"### "<<i<<" ###"<<endl;
        if(op[i]==1){
            adding(1,0,n-1,left[i],right[i],height[i],t,actu);
        }
        else{
            removing(1,0,n-1,left[i],right[i],height[i],t,actu);
        }
    }
    vector<int> ans(n);
    recover(1,0,n-1,t,actu,ans);
    for(int i=0; i<n; i++){
        finalHeight[i] = (int)ans[i];
    }
    return;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 108 ms 14044 KB Output is correct
3 Correct 128 ms 9832 KB Output is correct
4 Correct 367 ms 31164 KB Output is correct
5 Correct 212 ms 31568 KB Output is correct
6 Correct 209 ms 30032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 2 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -