Submission #827453

# Submission time Handle Problem Language Result Execution time Memory
827453 2023-08-16T13:34:49 Z GrindMachine Radio Towers (IOI22_towers) C++17
11 / 100
4000 ms 4088 KB
// Om Namah Shivaya

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define conts continue
#define sz(a) a.size()

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &x, T y){
  x = min(x,y);
}

template<typename T>
void amax(T &x, T y){
  x = max(x,y);
}

#define debug(x) cout << #x << " = "; cout << x; cout << endl

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = 1e9 + 5;
const ll inf2 = (ll)1e18 + 5;

#include "towers.h"

template<typename T>
struct segtree{
    struct data{
        ll a;
    };

    data d_neutral = {-inf2};

    data merge(data &left, data &right){
        data curr;
        curr.a = max(left.a,right.a);
        return curr;
    }

    void modify(int i, T v){
        tr[i].a = v;
    }

    int n;
    vector<data> tr;

    segtree(int n_){
        n = n_;
        tr.assign(2*n+5,d_neutral);
    }

    void pupd(int i, T v){
        modify(i+n,v);
        for(i = (i+n)>>1; i; i >>= 1){
            tr[i] = merge(tr[i<<1],tr[i<<1|1]);
        }
    }

    data query(int l, int r){
        data res = d_neutral;

        for(l += n, r += n; l <= r; l >>= 1, r >>= 1){
            if(l & 1){
                res = merge(res,tr[l++]);
            }
            if(!(r & 1)){
                res = merge(res,tr[r--]);
            }
        }

        return res;
    }
};

int n;
vector<int> a;

void init(int n_, std::vector<int> a_) {
    n = n_;
    a = a_;    
}

int max_towers(int L, int R, int D) {
    vector<int> b;
    for(int i = L; i <= R; ++i){
        b.pb(a[i]);
    }
    int m = sz(b);

    segtree<int> st(m+5);
    rep(i,m) st.pupd(i,b[i]);

    vector<int> lx(m,-1), rx(m,inf1);
    rep(i,m){
        int lo = 0, hi = i-1;
        while(lo <= hi){
            int mid = (lo+hi) >> 1;
            int mx = st.query(mid,i-1).a;
            if(b[i] <= mx-D){
                lx[i] = mid-1;
                lo = mid+1;
            }
            else{
                hi = mid-1;
            }
        }

        lo = i+1, hi = m-1;
        while(lo <= hi){
            int mid = (lo+hi) >> 1;
            int mx = st.query(i+1,mid).a;
            if(b[i] <= mx-D){
                rx[i] = mid+1;
                hi = mid-1;
            }
            else{
                lo = mid+1;
            }
        }
    }

    vector<int> dp(m);
    rep(i,m){
        dp[i] = 1;
        rep(j,i){
            if(j <= lx[i] and i >= rx[j]){
                amax(dp[i],dp[j]+1);
            }
        }
    }

    int ans = *max_element(all(dp));
    return ans;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 2340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 372 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 4 ms 336 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 336 KB Output is correct
23 Correct 3 ms 336 KB Output is correct
24 Correct 4 ms 336 KB Output is correct
25 Correct 2 ms 208 KB Output is correct
26 Correct 4 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 4 ms 336 KB Output is correct
29 Correct 4 ms 336 KB Output is correct
30 Correct 4 ms 336 KB Output is correct
31 Correct 4 ms 336 KB Output is correct
32 Correct 4 ms 336 KB Output is correct
33 Correct 4 ms 336 KB Output is correct
34 Correct 4 ms 392 KB Output is correct
35 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 372 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 4 ms 336 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 336 KB Output is correct
23 Correct 3 ms 336 KB Output is correct
24 Correct 4 ms 336 KB Output is correct
25 Correct 2 ms 208 KB Output is correct
26 Correct 4 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 4 ms 336 KB Output is correct
29 Correct 4 ms 336 KB Output is correct
30 Correct 4 ms 336 KB Output is correct
31 Correct 4 ms 336 KB Output is correct
32 Correct 4 ms 336 KB Output is correct
33 Correct 4 ms 336 KB Output is correct
34 Correct 4 ms 392 KB Output is correct
35 Correct 5 ms 380 KB Output is correct
36 Correct 240 ms 1436 KB Output is correct
37 Correct 744 ms 2316 KB Output is correct
38 Correct 169 ms 1480 KB Output is correct
39 Correct 407 ms 2084 KB Output is correct
40 Correct 128 ms 1600 KB Output is correct
41 Correct 3237 ms 3680 KB Output is correct
42 Correct 13 ms 1360 KB Output is correct
43 Correct 954 ms 2732 KB Output is correct
44 Correct 93 ms 1472 KB Output is correct
45 Correct 19 ms 1440 KB Output is correct
46 Correct 11 ms 1384 KB Output is correct
47 Correct 1255 ms 2416 KB Output is correct
48 Correct 261 ms 1784 KB Output is correct
49 Correct 47 ms 1444 KB Output is correct
50 Correct 184 ms 1728 KB Output is correct
51 Correct 555 ms 2348 KB Output is correct
52 Execution timed out 4043 ms 4088 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4038 ms 2508 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4041 ms 1524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 336 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 208 KB Output is correct
16 Correct 3 ms 372 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 1 ms 208 KB Output is correct
20 Correct 4 ms 336 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 336 KB Output is correct
23 Correct 3 ms 336 KB Output is correct
24 Correct 4 ms 336 KB Output is correct
25 Correct 2 ms 208 KB Output is correct
26 Correct 4 ms 336 KB Output is correct
27 Correct 4 ms 336 KB Output is correct
28 Correct 4 ms 336 KB Output is correct
29 Correct 4 ms 336 KB Output is correct
30 Correct 4 ms 336 KB Output is correct
31 Correct 4 ms 336 KB Output is correct
32 Correct 4 ms 336 KB Output is correct
33 Correct 4 ms 336 KB Output is correct
34 Correct 4 ms 392 KB Output is correct
35 Correct 5 ms 380 KB Output is correct
36 Correct 240 ms 1436 KB Output is correct
37 Correct 744 ms 2316 KB Output is correct
38 Correct 169 ms 1480 KB Output is correct
39 Correct 407 ms 2084 KB Output is correct
40 Correct 128 ms 1600 KB Output is correct
41 Correct 3237 ms 3680 KB Output is correct
42 Correct 13 ms 1360 KB Output is correct
43 Correct 954 ms 2732 KB Output is correct
44 Correct 93 ms 1472 KB Output is correct
45 Correct 19 ms 1440 KB Output is correct
46 Correct 11 ms 1384 KB Output is correct
47 Correct 1255 ms 2416 KB Output is correct
48 Correct 261 ms 1784 KB Output is correct
49 Correct 47 ms 1444 KB Output is correct
50 Correct 184 ms 1728 KB Output is correct
51 Correct 555 ms 2348 KB Output is correct
52 Execution timed out 4043 ms 4088 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 2340 KB Time limit exceeded
2 Halted 0 ms 0 KB -