Submission #835130

# Submission time Handle Problem Language Result Execution time Memory
835130 2023-08-23T08:51:49 Z gagik_2007 Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 12144 KB
#include "towers.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define ff first
#define ss second

ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=100007;
ll n,m,k;
vector<int>a;
struct Node{
    int mx;
    int mxind;
    int mn;
    int mnind;
    Node():mx(0),mn(0),mxind(0),mnind(0){}
    void bld(int vl, int ind){
        mx=mn=vl;
        mxind=mnind=ind;
    }
    void join(const Node& lft, const Node& rgh){
        if(lft.mx>=rgh.mx){
            mx=lft.mx;
            mxind=lft.mxind;
        }
        else{
            mx=rgh.mx;
            mxind=rgh.mxind;
        }
        if(lft.mn<=rgh.mn){
            mn=lft.mn;
            mnind=lft.mnind;
        }
        else{
            mn=rgh.mn;
            mnind=rgh.mnind;
        }
    }
};
Node t[4*N];

void build(int v, int tl, int tr){
    if(tl==tr){
        t[v].bld(a[tl], tl);
    }
    else{
        int tm=(tl+tr)/2;
        build(2*v,tl,tm);
        build(2*v+1,tm+1,tr);
        t[v].join(t[2*v],t[2*v+1]);
    }
}

pair<int,int> get_max(int v, int tl, int tr, int l, int r){
    if(l>r)return {0,0};
    if(tl==l&&tr==r)return {t[v].mx, t[v].mxind};
    else{
        int tm=(tl+tr)/2;
        return max(get_max(2*v,tl,tm,l,min(tm,r)),
            get_max(2*v+1,tm+1,tr,max(tm+1,l),r));
    }
}

pair<int,int> get_min(int v, int tl, int tr, int l, int r){
    if(l>r)return {MOD,MOD};
    if(tl==l&&tr==r)return {t[v].mn,t[v].mnind};
    else{
        int tm=(tl+tr)/2;
        return min(get_min(2*v,tl,tm,l,min(tm,r)),
            get_min(2*v+1,tm+1,tr,max(tm+1,l),r));
    }
}

int recurs(int l, int r, int vl, int d){
    if(l>r)return 0;
    int mx=get_max(1,0,n-1,l,r).ss,
        mn=get_min(1,0,n-1,l,r).ss;
    if(a[mn]>vl-d)return 0;
    int lft=recurs(l,mx-1,a[mx],d);
    int rgh=recurs(mx+1,r,a[mx],d);
    // cout<<l<<" "<<r<<" "<<vl<<" "<<d<<": ";
    // cout<<a[mn]<<", "<<a[mx]<<", ";
    if(lft==0&&rgh==0){
        // cout<<1<<endl;
        return 1;
    }
    // cout<<lft+rgh<<endl;
    return lft+rgh;
}

void init(int NN, vector<int> H) {
    n=NN;
    a=H;
    build(1,0,n-1);
}

int max_towers(int L, int R, int D) {
    return recurs(L,R,2e9+7,D);
}

Compilation message

towers.cpp: In constructor 'Node::Node()':
towers.cpp:22:9: warning: 'Node::mn' will be initialized after [-Wreorder]
   22 |     int mn;
      |         ^~
towers.cpp:21:9: warning:   'int Node::mxind' [-Wreorder]
   21 |     int mxind;
      |         ^~~~~
towers.cpp:24:5: warning:   when initialized here [-Wreorder]
   24 |     Node():mx(0),mn(0),mxind(0),mnind(0){}
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4090 ms 9208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 5 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 3 ms 6608 KB Output is correct
14 Correct 3 ms 6608 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 4 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 3 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 3 ms 6480 KB Output is correct
22 Correct 3 ms 6480 KB Output is correct
23 Correct 3 ms 6608 KB Output is correct
24 Correct 3 ms 6608 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 4 ms 6480 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 3 ms 6480 KB Output is correct
30 Correct 3 ms 6480 KB Output is correct
31 Correct 4 ms 6480 KB Output is correct
32 Correct 5 ms 6608 KB Output is correct
33 Correct 3 ms 6608 KB Output is correct
34 Correct 3 ms 6480 KB Output is correct
35 Correct 4 ms 6608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 5 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 3 ms 6608 KB Output is correct
14 Correct 3 ms 6608 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 4 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 3 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 3 ms 6480 KB Output is correct
22 Correct 3 ms 6480 KB Output is correct
23 Correct 3 ms 6608 KB Output is correct
24 Correct 3 ms 6608 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 4 ms 6480 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 3 ms 6480 KB Output is correct
30 Correct 3 ms 6480 KB Output is correct
31 Correct 4 ms 6480 KB Output is correct
32 Correct 5 ms 6608 KB Output is correct
33 Correct 3 ms 6608 KB Output is correct
34 Correct 3 ms 6480 KB Output is correct
35 Correct 4 ms 6608 KB Output is correct
36 Correct 18 ms 7248 KB Output is correct
37 Correct 18 ms 7632 KB Output is correct
38 Correct 16 ms 7708 KB Output is correct
39 Correct 13 ms 7632 KB Output is correct
40 Correct 17 ms 7728 KB Output is correct
41 Correct 36 ms 7632 KB Output is correct
42 Correct 16 ms 7740 KB Output is correct
43 Correct 25 ms 8868 KB Output is correct
44 Correct 12 ms 7632 KB Output is correct
45 Correct 12 ms 7724 KB Output is correct
46 Correct 15 ms 7704 KB Output is correct
47 Correct 24 ms 7760 KB Output is correct
48 Correct 18 ms 7632 KB Output is correct
49 Correct 15 ms 7632 KB Output is correct
50 Correct 20 ms 8256 KB Output is correct
51 Correct 27 ms 9276 KB Output is correct
52 Correct 48 ms 7632 KB Output is correct
53 Correct 46 ms 7632 KB Output is correct
54 Correct 39 ms 7632 KB Output is correct
55 Correct 42 ms 12144 KB Output is correct
56 Correct 43 ms 11532 KB Output is correct
57 Correct 30 ms 7584 KB Output is correct
58 Correct 43 ms 7736 KB Output is correct
59 Correct 47 ms 7704 KB Output is correct
60 Correct 47 ms 7632 KB Output is correct
61 Correct 39 ms 7632 KB Output is correct
62 Correct 41 ms 7632 KB Output is correct
63 Correct 41 ms 7700 KB Output is correct
64 Correct 24 ms 9632 KB Output is correct
65 Correct 25 ms 9436 KB Output is correct
66 Correct 29 ms 9024 KB Output is correct
67 Correct 27 ms 9512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4093 ms 7720 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4005 ms 6736 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6480 KB Output is correct
2 Correct 3 ms 6480 KB Output is correct
3 Correct 3 ms 6480 KB Output is correct
4 Correct 3 ms 6480 KB Output is correct
5 Correct 3 ms 6480 KB Output is correct
6 Correct 3 ms 6480 KB Output is correct
7 Correct 3 ms 6480 KB Output is correct
8 Correct 3 ms 6480 KB Output is correct
9 Correct 3 ms 6480 KB Output is correct
10 Correct 3 ms 6480 KB Output is correct
11 Correct 5 ms 6480 KB Output is correct
12 Correct 3 ms 6480 KB Output is correct
13 Correct 3 ms 6608 KB Output is correct
14 Correct 3 ms 6608 KB Output is correct
15 Correct 3 ms 6480 KB Output is correct
16 Correct 4 ms 6480 KB Output is correct
17 Correct 3 ms 6480 KB Output is correct
18 Correct 3 ms 6480 KB Output is correct
19 Correct 3 ms 6480 KB Output is correct
20 Correct 3 ms 6480 KB Output is correct
21 Correct 3 ms 6480 KB Output is correct
22 Correct 3 ms 6480 KB Output is correct
23 Correct 3 ms 6608 KB Output is correct
24 Correct 3 ms 6608 KB Output is correct
25 Correct 3 ms 6480 KB Output is correct
26 Correct 3 ms 6480 KB Output is correct
27 Correct 4 ms 6480 KB Output is correct
28 Correct 3 ms 6480 KB Output is correct
29 Correct 3 ms 6480 KB Output is correct
30 Correct 3 ms 6480 KB Output is correct
31 Correct 4 ms 6480 KB Output is correct
32 Correct 5 ms 6608 KB Output is correct
33 Correct 3 ms 6608 KB Output is correct
34 Correct 3 ms 6480 KB Output is correct
35 Correct 4 ms 6608 KB Output is correct
36 Correct 18 ms 7248 KB Output is correct
37 Correct 18 ms 7632 KB Output is correct
38 Correct 16 ms 7708 KB Output is correct
39 Correct 13 ms 7632 KB Output is correct
40 Correct 17 ms 7728 KB Output is correct
41 Correct 36 ms 7632 KB Output is correct
42 Correct 16 ms 7740 KB Output is correct
43 Correct 25 ms 8868 KB Output is correct
44 Correct 12 ms 7632 KB Output is correct
45 Correct 12 ms 7724 KB Output is correct
46 Correct 15 ms 7704 KB Output is correct
47 Correct 24 ms 7760 KB Output is correct
48 Correct 18 ms 7632 KB Output is correct
49 Correct 15 ms 7632 KB Output is correct
50 Correct 20 ms 8256 KB Output is correct
51 Correct 27 ms 9276 KB Output is correct
52 Correct 48 ms 7632 KB Output is correct
53 Correct 46 ms 7632 KB Output is correct
54 Correct 39 ms 7632 KB Output is correct
55 Correct 42 ms 12144 KB Output is correct
56 Correct 43 ms 11532 KB Output is correct
57 Correct 30 ms 7584 KB Output is correct
58 Correct 43 ms 7736 KB Output is correct
59 Correct 47 ms 7704 KB Output is correct
60 Correct 47 ms 7632 KB Output is correct
61 Correct 39 ms 7632 KB Output is correct
62 Correct 41 ms 7632 KB Output is correct
63 Correct 41 ms 7700 KB Output is correct
64 Correct 24 ms 9632 KB Output is correct
65 Correct 25 ms 9436 KB Output is correct
66 Correct 29 ms 9024 KB Output is correct
67 Correct 27 ms 9512 KB Output is correct
68 Execution timed out 4093 ms 7720 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4090 ms 9208 KB Time limit exceeded
2 Halted 0 ms 0 KB -