Submission #717153

# Submission time Handle Problem Language Result Execution time Memory
717153 2023-04-01T09:31:58 Z Urvuk3 Wall (IOI14_wall) C++17
100 / 100
887 ms 99468 KB
#include "wall.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

vector<pii> seg;

pii Merge(pii p,pii q){
    if(p.fi<=q.fi && q.fi<=p.se) p.fi=q.fi;
    else if(q.fi>p.se){
        p.fi=q.fi;
        p.se=q.fi;
    }
    if(p.fi<=q.se && q.se<=p.se) p.se=q.se;
    else if(q.se<p.fi){
        p.fi=q.se;
        p.se=q.se;
    }
    return p;
}

void Propagate(int node,int l,int r){
    if(l!=r){
        seg[2*node]=Merge(seg[2*node],seg[node]);
        seg[2*node+1]=Merge(seg[2*node+1],seg[node]);
        seg[node]={0,INF};
    }
}

void UpdateR(int node,int l,int r,int L,int R,int x){
    Propagate(node,l,r);
    if(L<=l && r<=R){
        seg[node]=Merge(seg[node],{0,x});
        return;
    }
    if(L<=mid) UpdateR(2*node,l,mid,L,R,x);
    if(R>mid) UpdateR(2*node+1,mid+1,r,L,R,x);
}

void UpdateL(int node,int l,int r,int L,int R,int x){
    Propagate(node,l,r);
    if(L<=l && r<=R){
        seg[node]=Merge(seg[node],{x,INF});
        return;
    }
    if(L<=mid) UpdateL(2*node,l,mid,L,R,x);
    if(R>mid) UpdateL(2*node+1,mid+1,r,L,R,x);
}

pii Query(int node,int l,int r,int idx){
    if(l==r){
        return seg[node];
    }
    pii q;
    if(idx<=mid) q=Query(2*node,l,mid,idx);
    else q=Query(2*node+1,mid+1,r,idx);
    return Merge(q,seg[node]);
}

void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]){
    seg.resize(4*n+1,{0,INF});
    for(int i=0;i<k;i++){
        int tp=op[i];
        int l=left[i];
        int r=right[i];
        int x=height[i];
        if(tp==1) UpdateL(1,0,n-1,l,r,x);
        else UpdateR(1,0,n-1,l,r,x);
    }
    for(int i=0;i<n;i++){
        pii q=Query(1,0,n-1,i);
        finalHeight[i]=q.fi;
    }
    return;
}

/*
10 6
1 1 8 4
2 4 9 1
2 3 6 5
1 0 5 3
1 2 2 5
2 6 7 0
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 440 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 140 ms 13932 KB Output is correct
3 Correct 193 ms 7964 KB Output is correct
4 Correct 439 ms 21452 KB Output is correct
5 Correct 253 ms 22476 KB Output is correct
6 Correct 243 ms 20836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 440 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 7 ms 852 KB Output is correct
5 Correct 5 ms 852 KB Output is correct
6 Correct 6 ms 880 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 137 ms 13940 KB Output is correct
9 Correct 194 ms 7952 KB Output is correct
10 Correct 429 ms 21440 KB Output is correct
11 Correct 250 ms 22504 KB Output is correct
12 Correct 232 ms 20848 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 144 ms 13864 KB Output is correct
15 Correct 32 ms 1968 KB Output is correct
16 Correct 532 ms 21656 KB Output is correct
17 Correct 243 ms 21088 KB Output is correct
18 Correct 257 ms 21076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 6 ms 824 KB Output is correct
5 Correct 5 ms 820 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 1 ms 296 KB Output is correct
8 Correct 136 ms 13932 KB Output is correct
9 Correct 191 ms 7968 KB Output is correct
10 Correct 455 ms 21472 KB Output is correct
11 Correct 288 ms 22460 KB Output is correct
12 Correct 238 ms 20904 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 139 ms 13944 KB Output is correct
15 Correct 32 ms 2028 KB Output is correct
16 Correct 575 ms 21644 KB Output is correct
17 Correct 253 ms 21128 KB Output is correct
18 Correct 248 ms 21096 KB Output is correct
19 Correct 836 ms 99356 KB Output is correct
20 Correct 887 ms 96868 KB Output is correct
21 Correct 832 ms 99248 KB Output is correct
22 Correct 828 ms 96840 KB Output is correct
23 Correct 843 ms 96856 KB Output is correct
24 Correct 822 ms 96932 KB Output is correct
25 Correct 841 ms 96812 KB Output is correct
26 Correct 839 ms 99468 KB Output is correct
27 Correct 865 ms 99260 KB Output is correct
28 Correct 837 ms 96760 KB Output is correct
29 Correct 833 ms 96984 KB Output is correct
30 Correct 836 ms 96784 KB Output is correct