Submission #1007522

# Submission time Handle Problem Language Result Execution time Memory
1007522 2024-06-25T06:24:15 Z Mardonbekhazratov Wall (IOI14_wall) C++17
0 / 100
98 ms 13948 KB
#include "wall.h"
#include<bits/stdc++.h>

using namespace std;

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

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

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

    void push(int v){
        if(mn[v]!=-1){
            mn[v<<1]=mn[v<<1|1]=mn[v];
            tree[v<<1]=min(tree[v<<1],mn[v]);
            tree[v<<1|1]=min(tree[v<<1|1],mn[v]);
            mn[v]=-1;
        }
        if(mx[v]!=-1){
            mx[v<<1]=mx[v<<1|1]=mx[v];
            tree[v<<1]=max(tree[v<<1],mx[v]);
            tree[v<<1|1]=max(tree[v<<1|1],mx[v]);
            mx[v]=-1;
        }
    }

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

        int mid=(l+r)/2;

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

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

    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]);
    }
    for(int i=0;i<n;i++){
        finalHeight[i]=S.get(i);
        if(finalHeight[i]==-1) finalHeight[i]++;
    }
    return;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 79 ms 13948 KB Output is correct
3 Incorrect 98 ms 8276 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 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 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -