Submission #1007994

# Submission time Handle Problem Language Result Execution time Memory
1007994 2024-06-26T05:15:47 Z Mardonbekhazratov Wall (IOI14_wall) C++17
100 / 100
559 ms 59520 KB
#include "wall.h"
#include<bits/stdc++.h>
#define ff first
#define ss second

using namespace std;

struct SegTree{
    int N;
    const int INF=1e9;
    vector<int>mn,mx;

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

        mn.assign(2*N,INF);
        mx.assign(2*N,0);
    }

    void impact(int v,int x,int id){
        if(id&1){
            mx[v]=max(mx[v],x);
            if(mn[v]<x){
                if(v<N){
                    impact(v<<1,mn[v],2);
                    impact(v<<1|1,mn[v],2);
                }
                mn[v]=INF;
            }
        }
        else{
            mn[v]=min(mn[v],x);
            if(mx[v]>mn[v]) mx[v]=mn[v];
        }
    }

    void push(int v){
        if(mx[v]!=0){
            impact(v<<1,mx[v],1);
            impact(v<<1|1,mx[v],1);
            mx[v]=0;
        }
        if(mn[v]!=INF){
            impact(v<<1,mn[v],2);
            impact(v<<1|1,mn[v],2);
            mn[v]=INF;
        }
    }

    void update(int v,int l,int r,int ql,int qr,int x,int id,int c){
        if(ql>=r || l>=qr) return;
        if(l>=ql && qr>=r){
            impact(v,x,id);
            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 min(mn[v],mx[v]);
        }

        push(v);
        // cout<<tree[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);
        // cout<<'\n';
    }
    return;
}

# 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 Correct 1 ms 348 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 3 ms 860 KB Output is correct
6 Correct 3 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 109 ms 13824 KB Output is correct
3 Correct 101 ms 8016 KB Output is correct
4 Correct 268 ms 20372 KB Output is correct
5 Correct 153 ms 20792 KB Output is correct
6 Correct 154 ms 19280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 580 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 7 ms 704 KB Output is correct
5 Correct 3 ms 856 KB Output is correct
6 Correct 3 ms 708 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 83 ms 13836 KB Output is correct
9 Correct 94 ms 8020 KB Output is correct
10 Correct 309 ms 20184 KB Output is correct
11 Correct 151 ms 20816 KB Output is correct
12 Correct 176 ms 19284 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 92 ms 13908 KB Output is correct
15 Correct 27 ms 1880 KB Output is correct
16 Correct 495 ms 20284 KB Output is correct
17 Correct 163 ms 19536 KB Output is correct
18 Correct 194 ms 19688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 5 ms 860 KB Output is correct
5 Correct 5 ms 1116 KB Output is correct
6 Correct 3 ms 856 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 82 ms 13904 KB Output is correct
9 Correct 100 ms 8016 KB Output is correct
10 Correct 271 ms 20304 KB Output is correct
11 Correct 205 ms 20816 KB Output is correct
12 Correct 147 ms 19268 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 92 ms 13904 KB Output is correct
15 Correct 29 ms 1884 KB Output is correct
16 Correct 559 ms 20180 KB Output is correct
17 Correct 166 ms 19532 KB Output is correct
18 Correct 175 ms 19540 KB Output is correct
19 Correct 462 ms 59216 KB Output is correct
20 Correct 505 ms 59224 KB Output is correct
21 Correct 433 ms 59176 KB Output is correct
22 Correct 459 ms 59216 KB Output is correct
23 Correct 507 ms 59144 KB Output is correct
24 Correct 459 ms 59304 KB Output is correct
25 Correct 480 ms 59220 KB Output is correct
26 Correct 472 ms 59192 KB Output is correct
27 Correct 421 ms 59272 KB Output is correct
28 Correct 440 ms 59220 KB Output is correct
29 Correct 462 ms 59332 KB Output is correct
30 Correct 438 ms 59520 KB Output is correct