Submission #1023033

# Submission time Handle Problem Language Result Execution time Memory
1023033 2024-07-14T08:53:16 Z vjudge1 Radio Towers (IOI22_towers) C++17
37 / 100
4000 ms 25032 KB
#include "towers.h"
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>

const int MAX=2e5+10;
const int inf=1e9;

struct segtree{
    int mx[4*MAX],mn[4*MAX],pmx[4*MAX];

    void build(int v,int tl,int tr,vector<int> &H){
        if(tl==tr){
            mx[v]=mn[v]=H[tl];
            pmx[v]=tl;
            return;
        }
        int tm=(tl+tr)/2;
        build(2*v,tl,tm,H);
        build(2*v+1,tm+1,tr,H);
        mx[v]=max(mx[2*v],mx[2*v+1]);
        if(mx[2*v]>mx[2*v+1])pmx[v]=pmx[2*v];
        else pmx[v]=pmx[2*v+1];
        mn[v]=min(mn[2*v],mn[2*v+1]);
    }

    int getMn(int v,int tl,int tr,int l,int r){
        if(l>r||tl>r||l>tr)return inf;
        if(l<=tl&&tr<=r)return mn[v];
        int tm=(tl+tr)/2;
        return min(getMn(2*v,tl,tm,l,r),getMn(2*v+1,tm+1,tr,l,r));
    }

    pii getMx(int v,int tl,int tr,int l,int r){
        if(l>r||tl>r||l>tr)return {-inf,-inf};
        if(l<=tl&&tr<=r)return {mx[v],pmx[v]};
        int tm=(tl+tr)/2;
        return max(getMx(2*v,tl,tm,l,r),getMx(2*v+1,tm+1,tr,l,r));
    }
}T;

int n,root;
vector<int> g[MAX];
int p[MAX];
int posMx=0;
bool sub;
vector<int> h;

int make_tree(int l,int r){
    if(l>r)return -1;
    auto [mx,pos]=T.getMx(1,0,n-1,l,r);
    int pos1=make_tree(l,pos-1);
    int pos2=make_tree(pos+1,r);
    if(pos1!=-1){
        g[pos].pb(pos1);
    }
    if(pos2!=-1)g[pos].pb(pos2);
    return pos;
}

void init(int N, vector<int> H) {

    sub=1;
    int cnt=0;
    for(int i=1;i<N-1;i++){
        if(H[i]>H[i-1]&&H[i]<H[i+1])cnt++;
    }
    if(N>1){
        cnt+=(H[1]>H[0]);
        cnt+=(H[N-2]<H[N-1]);
    }
    if(cnt!=1)sub=0;
    for(int i=0;i<N;i++){
        if(H[i]>H[posMx])posMx=i;
    }
    h=H;

    T.build(1,0,N-1,H);
    n=N;
    root=make_tree(0,n-1);
    p[0]=g[0].empty();
    for(int i=1;i<N;i++)p[i]=p[i-1]+(g[i].empty());
}

int get(int l,int r,int d,int g){
    if(l>r)return 0;
    int ans=0;
    if(T.getMn(1,0,n-1,l,r)<=g){
        ans=1;
    }
    auto [mx,pos]=T.getMx(1,0,n-1,l,r);
    ans=max(ans,get(l,pos-1,d,mx-d)+get(pos+1,r,d,mx-d));
    return ans;
}

int get1(int l,int r){
    if(l==r)return 1;
    int ans=p[r]-(l>0?p[l-1]:0);
    if(sz(g[l])==1&&g[l][0]<l)ans++;
    if(sz(g[r])==1&&g[r][0]>r)ans++;
    return ans;
}

int max_towers(int L, int R, int D) {
    if(sub){
        if(L<posMx&&posMx<R){
            if(h[posMx]-D>=max(h[L],h[R]))return 2;
            return 1;
        }
        else return 1;
    }
    if(D==1){
        return get1(L,R);
    }
    return get(L,R,D,inf);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4029 ms 15304 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5180 KB Output is correct
2 Correct 5 ms 5208 KB Output is correct
3 Correct 5 ms 5208 KB Output is correct
4 Correct 4 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 4 ms 5464 KB Output is correct
9 Correct 4 ms 5464 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 3 ms 5464 KB Output is correct
12 Correct 4 ms 4952 KB Output is correct
13 Correct 4 ms 5464 KB Output is correct
14 Correct 4 ms 5464 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 4 ms 5204 KB Output is correct
23 Correct 3 ms 5464 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 4 ms 5144 KB Output is correct
26 Correct 5 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 3 ms 5244 KB Output is correct
30 Correct 5 ms 5148 KB Output is correct
31 Correct 4 ms 5228 KB Output is correct
32 Correct 4 ms 5464 KB Output is correct
33 Correct 4 ms 5464 KB Output is correct
34 Correct 5 ms 5464 KB Output is correct
35 Correct 5 ms 5460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5180 KB Output is correct
2 Correct 5 ms 5208 KB Output is correct
3 Correct 5 ms 5208 KB Output is correct
4 Correct 4 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 4 ms 5464 KB Output is correct
9 Correct 4 ms 5464 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 3 ms 5464 KB Output is correct
12 Correct 4 ms 4952 KB Output is correct
13 Correct 4 ms 5464 KB Output is correct
14 Correct 4 ms 5464 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 4 ms 5204 KB Output is correct
23 Correct 3 ms 5464 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 4 ms 5144 KB Output is correct
26 Correct 5 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 3 ms 5244 KB Output is correct
30 Correct 5 ms 5148 KB Output is correct
31 Correct 4 ms 5228 KB Output is correct
32 Correct 4 ms 5464 KB Output is correct
33 Correct 4 ms 5464 KB Output is correct
34 Correct 5 ms 5464 KB Output is correct
35 Correct 5 ms 5460 KB Output is correct
36 Correct 37 ms 9040 KB Output is correct
37 Correct 66 ms 11728 KB Output is correct
38 Correct 37 ms 11856 KB Output is correct
39 Correct 49 ms 11176 KB Output is correct
40 Correct 44 ms 11340 KB Output is correct
41 Correct 51 ms 11344 KB Output is correct
42 Correct 51 ms 11344 KB Output is correct
43 Correct 51 ms 23632 KB Output is correct
44 Correct 46 ms 23780 KB Output is correct
45 Correct 37 ms 20728 KB Output is correct
46 Correct 50 ms 19540 KB Output is correct
47 Correct 31 ms 11684 KB Output is correct
48 Correct 30 ms 11344 KB Output is correct
49 Correct 48 ms 11344 KB Output is correct
50 Correct 33 ms 23628 KB Output is correct
51 Correct 37 ms 23496 KB Output is correct
52 Correct 32 ms 11860 KB Output is correct
53 Correct 35 ms 11172 KB Output is correct
54 Correct 29 ms 11352 KB Output is correct
55 Correct 33 ms 23632 KB Output is correct
56 Correct 39 ms 22740 KB Output is correct
57 Correct 58 ms 11664 KB Output is correct
58 Correct 54 ms 11708 KB Output is correct
59 Correct 55 ms 11828 KB Output is correct
60 Correct 79 ms 11344 KB Output is correct
61 Correct 51 ms 11348 KB Output is correct
62 Correct 49 ms 11344 KB Output is correct
63 Correct 49 ms 11352 KB Output is correct
64 Correct 60 ms 25028 KB Output is correct
65 Correct 58 ms 25032 KB Output is correct
66 Correct 58 ms 20168 KB Output is correct
67 Correct 49 ms 24264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 541 ms 11600 KB Output is correct
2 Correct 696 ms 11848 KB Output is correct
3 Correct 671 ms 11864 KB Output is correct
4 Correct 562 ms 11172 KB Output is correct
5 Correct 570 ms 11344 KB Output is correct
6 Correct 600 ms 11344 KB Output is correct
7 Correct 580 ms 11344 KB Output is correct
8 Correct 622 ms 23632 KB Output is correct
9 Correct 621 ms 23632 KB Output is correct
10 Correct 627 ms 21072 KB Output is correct
11 Correct 651 ms 21112 KB Output is correct
12 Correct 674 ms 23632 KB Output is correct
13 Correct 652 ms 23896 KB Output is correct
14 Correct 4 ms 4952 KB Output is correct
15 Correct 4 ms 5464 KB Output is correct
16 Correct 3 ms 5464 KB Output is correct
17 Correct 51 ms 11816 KB Output is correct
18 Correct 32 ms 11172 KB Output is correct
19 Correct 45 ms 11164 KB Output is correct
20 Correct 41 ms 23692 KB Output is correct
21 Correct 36 ms 23632 KB Output is correct
22 Correct 50 ms 11672 KB Output is correct
23 Correct 45 ms 11344 KB Output is correct
24 Correct 48 ms 11224 KB Output is correct
25 Correct 40 ms 23896 KB Output is correct
26 Correct 42 ms 22864 KB Output is correct
27 Correct 4 ms 5208 KB Output is correct
28 Correct 4 ms 5208 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 3 ms 5464 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5204 KB Output is correct
33 Correct 3 ms 5208 KB Output is correct
34 Correct 5 ms 5208 KB Output is correct
35 Correct 3 ms 5360 KB Output is correct
36 Correct 4 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4051 ms 6624 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5180 KB Output is correct
2 Correct 5 ms 5208 KB Output is correct
3 Correct 5 ms 5208 KB Output is correct
4 Correct 4 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 4 ms 5464 KB Output is correct
9 Correct 4 ms 5464 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 3 ms 5464 KB Output is correct
12 Correct 4 ms 4952 KB Output is correct
13 Correct 4 ms 5464 KB Output is correct
14 Correct 4 ms 5464 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 4 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 4 ms 5204 KB Output is correct
23 Correct 3 ms 5464 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 4 ms 5144 KB Output is correct
26 Correct 5 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 3 ms 5244 KB Output is correct
30 Correct 5 ms 5148 KB Output is correct
31 Correct 4 ms 5228 KB Output is correct
32 Correct 4 ms 5464 KB Output is correct
33 Correct 4 ms 5464 KB Output is correct
34 Correct 5 ms 5464 KB Output is correct
35 Correct 5 ms 5460 KB Output is correct
36 Correct 37 ms 9040 KB Output is correct
37 Correct 66 ms 11728 KB Output is correct
38 Correct 37 ms 11856 KB Output is correct
39 Correct 49 ms 11176 KB Output is correct
40 Correct 44 ms 11340 KB Output is correct
41 Correct 51 ms 11344 KB Output is correct
42 Correct 51 ms 11344 KB Output is correct
43 Correct 51 ms 23632 KB Output is correct
44 Correct 46 ms 23780 KB Output is correct
45 Correct 37 ms 20728 KB Output is correct
46 Correct 50 ms 19540 KB Output is correct
47 Correct 31 ms 11684 KB Output is correct
48 Correct 30 ms 11344 KB Output is correct
49 Correct 48 ms 11344 KB Output is correct
50 Correct 33 ms 23628 KB Output is correct
51 Correct 37 ms 23496 KB Output is correct
52 Correct 32 ms 11860 KB Output is correct
53 Correct 35 ms 11172 KB Output is correct
54 Correct 29 ms 11352 KB Output is correct
55 Correct 33 ms 23632 KB Output is correct
56 Correct 39 ms 22740 KB Output is correct
57 Correct 58 ms 11664 KB Output is correct
58 Correct 54 ms 11708 KB Output is correct
59 Correct 55 ms 11828 KB Output is correct
60 Correct 79 ms 11344 KB Output is correct
61 Correct 51 ms 11348 KB Output is correct
62 Correct 49 ms 11344 KB Output is correct
63 Correct 49 ms 11352 KB Output is correct
64 Correct 60 ms 25028 KB Output is correct
65 Correct 58 ms 25032 KB Output is correct
66 Correct 58 ms 20168 KB Output is correct
67 Correct 49 ms 24264 KB Output is correct
68 Correct 541 ms 11600 KB Output is correct
69 Correct 696 ms 11848 KB Output is correct
70 Correct 671 ms 11864 KB Output is correct
71 Correct 562 ms 11172 KB Output is correct
72 Correct 570 ms 11344 KB Output is correct
73 Correct 600 ms 11344 KB Output is correct
74 Correct 580 ms 11344 KB Output is correct
75 Correct 622 ms 23632 KB Output is correct
76 Correct 621 ms 23632 KB Output is correct
77 Correct 627 ms 21072 KB Output is correct
78 Correct 651 ms 21112 KB Output is correct
79 Correct 674 ms 23632 KB Output is correct
80 Correct 652 ms 23896 KB Output is correct
81 Correct 4 ms 4952 KB Output is correct
82 Correct 4 ms 5464 KB Output is correct
83 Correct 3 ms 5464 KB Output is correct
84 Correct 51 ms 11816 KB Output is correct
85 Correct 32 ms 11172 KB Output is correct
86 Correct 45 ms 11164 KB Output is correct
87 Correct 41 ms 23692 KB Output is correct
88 Correct 36 ms 23632 KB Output is correct
89 Correct 50 ms 11672 KB Output is correct
90 Correct 45 ms 11344 KB Output is correct
91 Correct 48 ms 11224 KB Output is correct
92 Correct 40 ms 23896 KB Output is correct
93 Correct 42 ms 22864 KB Output is correct
94 Correct 4 ms 5208 KB Output is correct
95 Correct 4 ms 5208 KB Output is correct
96 Correct 4 ms 5208 KB Output is correct
97 Correct 3 ms 5464 KB Output is correct
98 Correct 3 ms 5208 KB Output is correct
99 Correct 3 ms 5204 KB Output is correct
100 Correct 3 ms 5208 KB Output is correct
101 Correct 5 ms 5208 KB Output is correct
102 Correct 3 ms 5360 KB Output is correct
103 Correct 4 ms 5208 KB Output is correct
104 Execution timed out 4098 ms 11384 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4029 ms 15304 KB Time limit exceeded
2 Halted 0 ms 0 KB -