Submission #1023023

# Submission time Handle Problem Language Result Execution time Memory
1023023 2024-07-14T08:47:25 Z vjudge1 Radio Towers (IOI22_towers) C++17
37 / 100
4000 ms 24520 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 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) {
    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(D==1){
        return get1(L,R);
    }
    return get(L,R,D,inf);
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4013 ms 14992 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5036 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 5088 KB Output is correct
8 Correct 3 ms 5472 KB Output is correct
9 Correct 3 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 2 ms 4952 KB Output is correct
13 Correct 3 ms 5464 KB Output is correct
14 Correct 3 ms 5464 KB Output is correct
15 Correct 3 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 3 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5420 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5256 KB Output is correct
29 Correct 3 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5424 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 4 ms 5464 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5036 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 5088 KB Output is correct
8 Correct 3 ms 5472 KB Output is correct
9 Correct 3 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 2 ms 4952 KB Output is correct
13 Correct 3 ms 5464 KB Output is correct
14 Correct 3 ms 5464 KB Output is correct
15 Correct 3 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 3 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5420 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5256 KB Output is correct
29 Correct 3 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5424 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 4 ms 5464 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
36 Correct 25 ms 8792 KB Output is correct
37 Correct 43 ms 11352 KB Output is correct
38 Correct 32 ms 11292 KB Output is correct
39 Correct 34 ms 10836 KB Output is correct
40 Correct 30 ms 10832 KB Output is correct
41 Correct 47 ms 10840 KB Output is correct
42 Correct 37 ms 10832 KB Output is correct
43 Correct 46 ms 23376 KB Output is correct
44 Correct 37 ms 23376 KB Output is correct
45 Correct 42 ms 20408 KB Output is correct
46 Correct 33 ms 19280 KB Output is correct
47 Correct 28 ms 11348 KB Output is correct
48 Correct 28 ms 10840 KB Output is correct
49 Correct 28 ms 10832 KB Output is correct
50 Correct 31 ms 23376 KB Output is correct
51 Correct 40 ms 23120 KB Output is correct
52 Correct 31 ms 11348 KB Output is correct
53 Correct 30 ms 10832 KB Output is correct
54 Correct 28 ms 10840 KB Output is correct
55 Correct 31 ms 23264 KB Output is correct
56 Correct 42 ms 22352 KB Output is correct
57 Correct 48 ms 11352 KB Output is correct
58 Correct 52 ms 11252 KB Output is correct
59 Correct 51 ms 11464 KB Output is correct
60 Correct 53 ms 10736 KB Output is correct
61 Correct 46 ms 10840 KB Output is correct
62 Correct 47 ms 10840 KB Output is correct
63 Correct 47 ms 10832 KB Output is correct
64 Correct 51 ms 24520 KB Output is correct
65 Correct 47 ms 24520 KB Output is correct
66 Correct 63 ms 19760 KB Output is correct
67 Correct 52 ms 23752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 535 ms 11344 KB Output is correct
2 Correct 712 ms 11344 KB Output is correct
3 Correct 683 ms 11348 KB Output is correct
4 Correct 664 ms 10828 KB Output is correct
5 Correct 623 ms 10832 KB Output is correct
6 Correct 648 ms 10840 KB Output is correct
7 Correct 624 ms 10832 KB Output is correct
8 Correct 680 ms 23376 KB Output is correct
9 Correct 668 ms 23460 KB Output is correct
10 Correct 617 ms 20560 KB Output is correct
11 Correct 695 ms 20560 KB Output is correct
12 Correct 609 ms 23376 KB Output is correct
13 Correct 635 ms 23380 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 5464 KB Output is correct
16 Correct 3 ms 5464 KB Output is correct
17 Correct 30 ms 11352 KB Output is correct
18 Correct 30 ms 10840 KB Output is correct
19 Correct 29 ms 10840 KB Output is correct
20 Correct 36 ms 23468 KB Output is correct
21 Correct 33 ms 23120 KB Output is correct
22 Correct 37 ms 11344 KB Output is correct
23 Correct 26 ms 10848 KB Output is correct
24 Correct 28 ms 10820 KB Output is correct
25 Correct 30 ms 23468 KB Output is correct
26 Correct 35 ms 22360 KB Output is correct
27 Correct 2 ms 5208 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 3 ms 5208 KB Output is correct
30 Correct 3 ms 5464 KB Output is correct
31 Correct 2 ms 5260 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 3 ms 5192 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4037 ms 6488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 5208 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5036 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 5088 KB Output is correct
8 Correct 3 ms 5472 KB Output is correct
9 Correct 3 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 2 ms 4952 KB Output is correct
13 Correct 3 ms 5464 KB Output is correct
14 Correct 3 ms 5464 KB Output is correct
15 Correct 3 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 3 ms 5464 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 3 ms 5208 KB Output is correct
23 Correct 3 ms 5420 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 3 ms 5256 KB Output is correct
29 Correct 3 ms 5208 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 3 ms 5208 KB Output is correct
32 Correct 3 ms 5424 KB Output is correct
33 Correct 3 ms 5464 KB Output is correct
34 Correct 4 ms 5464 KB Output is correct
35 Correct 3 ms 5464 KB Output is correct
36 Correct 25 ms 8792 KB Output is correct
37 Correct 43 ms 11352 KB Output is correct
38 Correct 32 ms 11292 KB Output is correct
39 Correct 34 ms 10836 KB Output is correct
40 Correct 30 ms 10832 KB Output is correct
41 Correct 47 ms 10840 KB Output is correct
42 Correct 37 ms 10832 KB Output is correct
43 Correct 46 ms 23376 KB Output is correct
44 Correct 37 ms 23376 KB Output is correct
45 Correct 42 ms 20408 KB Output is correct
46 Correct 33 ms 19280 KB Output is correct
47 Correct 28 ms 11348 KB Output is correct
48 Correct 28 ms 10840 KB Output is correct
49 Correct 28 ms 10832 KB Output is correct
50 Correct 31 ms 23376 KB Output is correct
51 Correct 40 ms 23120 KB Output is correct
52 Correct 31 ms 11348 KB Output is correct
53 Correct 30 ms 10832 KB Output is correct
54 Correct 28 ms 10840 KB Output is correct
55 Correct 31 ms 23264 KB Output is correct
56 Correct 42 ms 22352 KB Output is correct
57 Correct 48 ms 11352 KB Output is correct
58 Correct 52 ms 11252 KB Output is correct
59 Correct 51 ms 11464 KB Output is correct
60 Correct 53 ms 10736 KB Output is correct
61 Correct 46 ms 10840 KB Output is correct
62 Correct 47 ms 10840 KB Output is correct
63 Correct 47 ms 10832 KB Output is correct
64 Correct 51 ms 24520 KB Output is correct
65 Correct 47 ms 24520 KB Output is correct
66 Correct 63 ms 19760 KB Output is correct
67 Correct 52 ms 23752 KB Output is correct
68 Correct 535 ms 11344 KB Output is correct
69 Correct 712 ms 11344 KB Output is correct
70 Correct 683 ms 11348 KB Output is correct
71 Correct 664 ms 10828 KB Output is correct
72 Correct 623 ms 10832 KB Output is correct
73 Correct 648 ms 10840 KB Output is correct
74 Correct 624 ms 10832 KB Output is correct
75 Correct 680 ms 23376 KB Output is correct
76 Correct 668 ms 23460 KB Output is correct
77 Correct 617 ms 20560 KB Output is correct
78 Correct 695 ms 20560 KB Output is correct
79 Correct 609 ms 23376 KB Output is correct
80 Correct 635 ms 23380 KB Output is correct
81 Correct 3 ms 4952 KB Output is correct
82 Correct 3 ms 5464 KB Output is correct
83 Correct 3 ms 5464 KB Output is correct
84 Correct 30 ms 11352 KB Output is correct
85 Correct 30 ms 10840 KB Output is correct
86 Correct 29 ms 10840 KB Output is correct
87 Correct 36 ms 23468 KB Output is correct
88 Correct 33 ms 23120 KB Output is correct
89 Correct 37 ms 11344 KB Output is correct
90 Correct 26 ms 10848 KB Output is correct
91 Correct 28 ms 10820 KB Output is correct
92 Correct 30 ms 23468 KB Output is correct
93 Correct 35 ms 22360 KB Output is correct
94 Correct 2 ms 5208 KB Output is correct
95 Correct 2 ms 5208 KB Output is correct
96 Correct 3 ms 5208 KB Output is correct
97 Correct 3 ms 5464 KB Output is correct
98 Correct 2 ms 5260 KB Output is correct
99 Correct 3 ms 5208 KB Output is correct
100 Correct 3 ms 5192 KB Output is correct
101 Correct 3 ms 5208 KB Output is correct
102 Correct 3 ms 5464 KB Output is correct
103 Correct 3 ms 5208 KB Output is correct
104 Execution timed out 4017 ms 11096 KB Time limit exceeded
105 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4013 ms 14992 KB Time limit exceeded
2 Halted 0 ms 0 KB -