Submission #432090

# Submission time Handle Problem Language Result Execution time Memory
432090 2021-06-17T20:24:22 Z REALITYNB Wall (IOI14_wall) C++17
100 / 100
2811 ms 208192 KB
#include <bits/stdc++.h>
#include "wall.h"
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
const int mxn = 5e6 , N =5e5+100 ;
vector<vector<int>> sg(2,vector<int>(mxn,-1));
int query(int t ,int in,int l ,int r ,int ql ,int qr){
    if(qr<l||r<ql) return -1 ;
    if(ql<=l&&r<=qr) return sg[t][in] ;
    int ans = query(t,in*2,l,(r+l)/2,ql,qr);
    ans=max(ans,query(t,in*2+1,(r+l)/2+1,r,ql,qr)) ;
    return ans;
}
int query(int i ,int t){
    if(t) i=N-i;
    return query(t,1,0,N,0,i);
}
void update(int t , int in, int l ,int r , int i,int v){
    if(i<l||r<i) return ;
    if(l==i&&r==i){
        sg[t][in]=v ;
        return ;
    }
    update(t,in*2,l,(r+l)/2,i,v);
    update(t,in*2+1,(l+r)/2+1,r,i,v);
    sg[t][in]=max(sg[t][in*2],sg[t][in*2+1]) ;
    //return sg[t][in] ;
}
void update(int i , int v , int t){
    if(t) i=N-i;
    update(t,1,0,N,i,v) ;
    return ;
}
void buildWall(int n,int k,int op[],int le[],int re[],int he[],int* ans){
    vector<vector<array<int,3>>> in(n) , out(n);
    set<int> ok ;
    for(int i=0;i<k;i++){
        if(op[i]==2) op[i]=0;
    }
    for(int i=0;i<k;i++) ok.insert(he[i]) ;
    ok.insert(0);
    int cnt =1;
    map<int,int> ki ,rk ;
    for(int x:ok) ki[x]=++cnt,rk[cnt]=x;
    for(int i=0;i<k;i++){
        in[le[i]].pb({op[i],ki[he[i]],i}) ;
        out[re[i]].pb({op[i],ki[he[i]],i});
    }
    set<int> hey[2][cnt+1];
    for(int i=0;i<n;i++){
        for(auto x  : in[i]){
            int t = x[0] , he = x[1],tim=x[2] ;
            hey[t][he].insert(tim) ;
            tim = *(--hey[t][he].end()) ;
            update(he,tim,t) ;
        }
        int l=1,r=cnt+1;
        while(r-l!=1){
            int md=(r+l)/2 ;
            int val = query(md-1,0) ,vall = query(md,1) ;
            if(vall>val) l=md ;
            else r=md;
        }
        ans[i]=rk[l];
        for(auto x: out[i]){
            int t=x[0],he=x[1],tim=x[2];
            hey[t][he].erase(tim) ;
            update(he,-1,t);
            if(hey[t][he].size()){
                update(he,*(--hey[t][he].end()),t);
            }
        }
    }
    return ;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 58916 KB Output is correct
2 Correct 39 ms 58892 KB Output is correct
3 Correct 35 ms 58976 KB Output is correct
4 Correct 96 ms 58892 KB Output is correct
5 Correct 93 ms 58944 KB Output is correct
6 Correct 96 ms 58920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 58884 KB Output is correct
2 Correct 1568 ms 106228 KB Output is correct
3 Correct 866 ms 76240 KB Output is correct
4 Correct 2811 ms 106736 KB Output is correct
5 Correct 963 ms 71780 KB Output is correct
6 Correct 839 ms 71708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 58948 KB Output is correct
2 Correct 39 ms 58924 KB Output is correct
3 Correct 35 ms 58888 KB Output is correct
4 Correct 95 ms 58956 KB Output is correct
5 Correct 94 ms 58956 KB Output is correct
6 Correct 101 ms 58912 KB Output is correct
7 Correct 33 ms 58900 KB Output is correct
8 Correct 1560 ms 106244 KB Output is correct
9 Correct 854 ms 76248 KB Output is correct
10 Correct 2731 ms 106544 KB Output is correct
11 Correct 951 ms 71812 KB Output is correct
12 Correct 825 ms 71688 KB Output is correct
13 Correct 29 ms 58956 KB Output is correct
14 Correct 1595 ms 106088 KB Output is correct
15 Correct 231 ms 58956 KB Output is correct
16 Correct 2683 ms 106748 KB Output is correct
17 Correct 886 ms 71120 KB Output is correct
18 Correct 887 ms 70724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 58900 KB Output is correct
2 Correct 40 ms 58956 KB Output is correct
3 Correct 39 ms 58892 KB Output is correct
4 Correct 97 ms 59000 KB Output is correct
5 Correct 93 ms 58960 KB Output is correct
6 Correct 93 ms 58956 KB Output is correct
7 Correct 29 ms 58960 KB Output is correct
8 Correct 1534 ms 106164 KB Output is correct
9 Correct 837 ms 76200 KB Output is correct
10 Correct 2673 ms 106444 KB Output is correct
11 Correct 962 ms 81868 KB Output is correct
12 Correct 832 ms 80260 KB Output is correct
13 Correct 29 ms 58956 KB Output is correct
14 Correct 1537 ms 111884 KB Output is correct
15 Correct 223 ms 58920 KB Output is correct
16 Correct 2626 ms 116332 KB Output is correct
17 Correct 898 ms 80188 KB Output is correct
18 Correct 878 ms 79796 KB Output is correct
19 Correct 2729 ms 208152 KB Output is correct
20 Correct 2690 ms 207964 KB Output is correct
21 Correct 2683 ms 207996 KB Output is correct
22 Correct 2659 ms 208100 KB Output is correct
23 Correct 2662 ms 207916 KB Output is correct
24 Correct 2697 ms 208016 KB Output is correct
25 Correct 2692 ms 207992 KB Output is correct
26 Correct 2681 ms 208016 KB Output is correct
27 Correct 2684 ms 208024 KB Output is correct
28 Correct 2658 ms 208008 KB Output is correct
29 Correct 2653 ms 207996 KB Output is correct
30 Correct 2668 ms 208192 KB Output is correct