답안 #1007531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007531 2024-06-25T06:43:17 Z Mardonbekhazratov 벽 (IOI14_wall) C++17
0 / 100
99 ms 8180 KB
#include "wall.h"
#include<bits/stdc++.h>
#define ff first
#define ss second

using namespace std;

struct SegTree{
    int N;
    vector<int>tree;
    vector<pair<int,int>>mn,mx;

    SegTree(int n){
        N=1;
        while(N<n) N<<=1;

        tree.assign(2*N,0);
        mn.assign(2*N,{-1,-1});
        mx.assign(2*N,{-1,-1});
    }

    void push1(int v){
        if(mx[v].ff==-1) return;
        mx[v<<1]=mx[v<<1|1]=mx[v];
        tree[v<<1]=max(tree[v<<1],mx[v].ff);
        tree[v<<1|1]=max(tree[v<<1|1],mx[v].ff);
        mx[v]={-1,-1};
    }

    void push2(int v){
        if(mn[v].ff==-1) return;
        mn[v<<1]=mn[v<<1|1]=mn[v];
        tree[v<<1]=min(tree[v<<1],mn[v].ff);
        tree[v<<1|1]=min(tree[v<<1|1],mn[v].ff);
        mn[v]={-1,-1};
    }

    void push(int v){
        if(mn[v].ss>mx[v].ss){
            push1(v);
            push2(v);
        }
        else if(mx[v].ff!=-1){
            push2(v);
            push1(v);
        }
    }

    void update(int v,int l,int r,int ql,int qr,int x,int id,int c){
        if(l>=qr || ql>=r) return;
        if(l>=ql && qr>=r){
            if(id&1) mx[v]={x,c},tree[v]=max(x,tree[v]);
            else mn[v]={x,c},tree[v]=min(tree[v],x);
            return;
        }
        push(v);

        int mid=(l+r)/2;

        update(v<<1,l,mid,ql,qr,x,id,c);
        update(v<<1|1,mid,r,ql,qr,x,id,c);
    }

    void update(int l,int r,int x,int id,int c){
        return update(1,0,N,l,r,x,id,c);
    }

    int get(int v,int l,int r,int id){
        if(r-l==1){
            return tree[v];
        }
        push(v);
        int mid=(l+r)/2;

        if(mid>id) return get(v<<1,l,mid,id);
        return get(v<<1|1,mid,r,id);
    }

    int get(int id){
        return get(1,0,N,id);
    }
};

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    SegTree S(n);
    for(int i=0;i<k;i++){
        S.update(left[i],right[i]+1,height[i],op[i],i);
    }
    for(int i=0;i<n;i++){
        finalHeight[i]=S.get(i);
    }
    return;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
2 Correct 78 ms 8180 KB Output is correct
3 Incorrect 99 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -