Submission #1007544

# Submission time Handle Problem Language Result Execution time Memory
1007544 2024-06-25T07:08:03 Z Mardonbekhazratov Wall (IOI14_wall) C++17
24 / 100
464 ms 23944 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;
    const int INF=1e9;

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

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

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

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

    void push(int v){
        if(mn[v].ss>mx[v].ss){
            push1(v);
            push2(v);
        }
        else{
            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(r-l>1) push(v);
            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;
}

# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 77 ms 8168 KB Output is correct
3 Correct 173 ms 5028 KB Output is correct
4 Correct 464 ms 23304 KB Output is correct
5 Correct 211 ms 23944 KB Output is correct
6 Correct 212 ms 22352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 -