Submission #907621

# Submission time Handle Problem Language Result Execution time Memory
907621 2024-01-16T00:24:49 Z vjudge1 Radio Towers (IOI22_towers) C++17
23 / 100
4000 ms 5144 KB
#include "towers.h"
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

#define NN 100010
#define M 1000000007 // 998244353

ll h[NN];
ll n;

namespace seg {
    typedef pl T;
    T id={-1, -1};
    T f(T a, T b) {return pair(max(a.K, b.K), max(a.V, b.V)) ;}

    T t[2 * NN];
    ll n=NN;  // array size

    void init(ll p, ll value) {  // set value at position p
      for (p+=n, t[p].K = value; p /= 2;) t[p] = f(t[2*p], t[2*p+1]);
    }

    void modify(ll p, ll value) {  // set value at position p
      for (p+=n, t[p].V = max(t[p].V, value); p /= 2;) t[p] = f(t[2*p], t[2*p+1]);
    }

    T query(ll l, ll r) { // fold f on interval [l, r)
      T resl=id, resr=id;
      for (l += n, r += n; l < r; l /= 2, r /= 2) {
        if (l&1) resl = f(resl, t[l++]);
        if (r&1) resr = f(t[--r], resr);
      }
      return f(resl, resr);
    }
}

void init(int N, std::vector<int> H) {
    n = N;
    F(i, 0, n) h[i] = H[i];

    F(i, 0, 2*NN) seg::t[i].V = -1;
    F(i, 0, n) seg::init(i, H[i]);
}

int max_towers(int L, int R, int D) {
    // vl dp(n+1, -1);/

    ll res = 0;
    // ll res2 = 0;
    F(i, L, R+1) {
        ll ans = 1;
        // ll ans2 = 1;
        {
            // for (ll cur = i-1; cur >= L; cur--) if (h[cur] >= D + h[i]) ans2 = max(ans2, dp[cur] + 1);

            ll l = L - 1, r = i + 1;
            while (l+1<r) {
                ll m = (l+r)/2;
                if (seg::query(m, i).K >= D + h[i]) l = m;
                else r = m;
            }

            // if (i == 5) {
            //     cout << L << " " << l+1 << " " << seg::query(L, l+1).V << " " << endl;
            //     cout << seg::query(l, l+1).V << endl;
            // }
            ans = max(ans, seg::query(L, l+1).V + 1);
        }
        {
            // for (ll cur = i+1; cur <= R; cur++) if (h[cur] >= D + h[i]) dp[cur] = max(dp[cur], ans2);

            ll l = i, r = R+1;
            while (l+1<r) {
                ll m = (l+r)/2;
                if (seg::query(i, m+1).K >= D + h[i]) r = m;
                else l = m;
            }
            seg::modify(r, ans); 

            // if (ans2 == 3) cout << "TURNEd 3 AT " << i << endl;
        }
        res = max(res, ans);
        // res2 = max(ans, ans2);
        // cout << "ARRAYS FOR  " << i << endl;
        // F(i, L, R+1) cout << dp[i] << " "; cout << endl;

        // F(i, L, R+1) cout << seg::query(i, i+1).V << " "; cout << endl;
        
    }
    // assert(res == res2);
    return res;


}
# Verdict Execution time Memory Grader output
1 Execution timed out 4014 ms 4268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 3 ms 3416 KB Output is correct
3 Correct 3 ms 3416 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 3 ms 3588 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 3 ms 3416 KB Output is correct
8 Correct 2 ms 3416 KB Output is correct
9 Correct 2 ms 3416 KB Output is correct
10 Correct 2 ms 3416 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 1 ms 3416 KB Output is correct
13 Correct 3 ms 3416 KB Output is correct
14 Correct 2 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 4 ms 3416 KB Output is correct
17 Correct 2 ms 3392 KB Output is correct
18 Correct 2 ms 3416 KB Output is correct
19 Correct 2 ms 3416 KB Output is correct
20 Correct 4 ms 3416 KB Output is correct
21 Correct 4 ms 3416 KB Output is correct
22 Correct 5 ms 3416 KB Output is correct
23 Correct 5 ms 3416 KB Output is correct
24 Correct 5 ms 3416 KB Output is correct
25 Correct 3 ms 3576 KB Output is correct
26 Correct 6 ms 3412 KB Output is correct
27 Correct 5 ms 3416 KB Output is correct
28 Correct 5 ms 3464 KB Output is correct
29 Correct 5 ms 3416 KB Output is correct
30 Correct 5 ms 3596 KB Output is correct
31 Correct 5 ms 3416 KB Output is correct
32 Correct 6 ms 3416 KB Output is correct
33 Correct 6 ms 3456 KB Output is correct
34 Correct 6 ms 3596 KB Output is correct
35 Correct 5 ms 3596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 3 ms 3416 KB Output is correct
3 Correct 3 ms 3416 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 3 ms 3588 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 3 ms 3416 KB Output is correct
8 Correct 2 ms 3416 KB Output is correct
9 Correct 2 ms 3416 KB Output is correct
10 Correct 2 ms 3416 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 1 ms 3416 KB Output is correct
13 Correct 3 ms 3416 KB Output is correct
14 Correct 2 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 4 ms 3416 KB Output is correct
17 Correct 2 ms 3392 KB Output is correct
18 Correct 2 ms 3416 KB Output is correct
19 Correct 2 ms 3416 KB Output is correct
20 Correct 4 ms 3416 KB Output is correct
21 Correct 4 ms 3416 KB Output is correct
22 Correct 5 ms 3416 KB Output is correct
23 Correct 5 ms 3416 KB Output is correct
24 Correct 5 ms 3416 KB Output is correct
25 Correct 3 ms 3576 KB Output is correct
26 Correct 6 ms 3412 KB Output is correct
27 Correct 5 ms 3416 KB Output is correct
28 Correct 5 ms 3464 KB Output is correct
29 Correct 5 ms 3416 KB Output is correct
30 Correct 5 ms 3596 KB Output is correct
31 Correct 5 ms 3416 KB Output is correct
32 Correct 6 ms 3416 KB Output is correct
33 Correct 6 ms 3456 KB Output is correct
34 Correct 6 ms 3596 KB Output is correct
35 Correct 5 ms 3596 KB Output is correct
36 Correct 57 ms 4544 KB Output is correct
37 Correct 152 ms 5092 KB Output is correct
38 Correct 56 ms 5128 KB Output is correct
39 Correct 137 ms 4940 KB Output is correct
40 Correct 51 ms 4932 KB Output is correct
41 Correct 310 ms 4932 KB Output is correct
42 Correct 30 ms 4936 KB Output is correct
43 Correct 224 ms 4952 KB Output is correct
44 Correct 64 ms 5132 KB Output is correct
45 Correct 29 ms 4940 KB Output is correct
46 Correct 25 ms 4940 KB Output is correct
47 Correct 104 ms 4936 KB Output is correct
48 Correct 67 ms 4936 KB Output is correct
49 Correct 37 ms 5136 KB Output is correct
50 Correct 83 ms 4940 KB Output is correct
51 Correct 136 ms 4952 KB Output is correct
52 Correct 302 ms 4932 KB Output is correct
53 Correct 299 ms 4940 KB Output is correct
54 Correct 303 ms 4936 KB Output is correct
55 Correct 382 ms 5132 KB Output is correct
56 Correct 367 ms 5140 KB Output is correct
57 Correct 387 ms 5080 KB Output is correct
58 Correct 382 ms 4932 KB Output is correct
59 Correct 350 ms 5144 KB Output is correct
60 Correct 301 ms 4952 KB Output is correct
61 Correct 340 ms 4952 KB Output is correct
62 Correct 373 ms 5112 KB Output is correct
63 Correct 333 ms 4952 KB Output is correct
64 Correct 453 ms 4936 KB Output is correct
65 Correct 463 ms 4944 KB Output is correct
66 Correct 447 ms 5112 KB Output is correct
67 Correct 466 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4061 ms 4928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4014 ms 3928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 3 ms 3416 KB Output is correct
3 Correct 3 ms 3416 KB Output is correct
4 Correct 2 ms 3416 KB Output is correct
5 Correct 3 ms 3588 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 3 ms 3416 KB Output is correct
8 Correct 2 ms 3416 KB Output is correct
9 Correct 2 ms 3416 KB Output is correct
10 Correct 2 ms 3416 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 1 ms 3416 KB Output is correct
13 Correct 3 ms 3416 KB Output is correct
14 Correct 2 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 4 ms 3416 KB Output is correct
17 Correct 2 ms 3392 KB Output is correct
18 Correct 2 ms 3416 KB Output is correct
19 Correct 2 ms 3416 KB Output is correct
20 Correct 4 ms 3416 KB Output is correct
21 Correct 4 ms 3416 KB Output is correct
22 Correct 5 ms 3416 KB Output is correct
23 Correct 5 ms 3416 KB Output is correct
24 Correct 5 ms 3416 KB Output is correct
25 Correct 3 ms 3576 KB Output is correct
26 Correct 6 ms 3412 KB Output is correct
27 Correct 5 ms 3416 KB Output is correct
28 Correct 5 ms 3464 KB Output is correct
29 Correct 5 ms 3416 KB Output is correct
30 Correct 5 ms 3596 KB Output is correct
31 Correct 5 ms 3416 KB Output is correct
32 Correct 6 ms 3416 KB Output is correct
33 Correct 6 ms 3456 KB Output is correct
34 Correct 6 ms 3596 KB Output is correct
35 Correct 5 ms 3596 KB Output is correct
36 Correct 57 ms 4544 KB Output is correct
37 Correct 152 ms 5092 KB Output is correct
38 Correct 56 ms 5128 KB Output is correct
39 Correct 137 ms 4940 KB Output is correct
40 Correct 51 ms 4932 KB Output is correct
41 Correct 310 ms 4932 KB Output is correct
42 Correct 30 ms 4936 KB Output is correct
43 Correct 224 ms 4952 KB Output is correct
44 Correct 64 ms 5132 KB Output is correct
45 Correct 29 ms 4940 KB Output is correct
46 Correct 25 ms 4940 KB Output is correct
47 Correct 104 ms 4936 KB Output is correct
48 Correct 67 ms 4936 KB Output is correct
49 Correct 37 ms 5136 KB Output is correct
50 Correct 83 ms 4940 KB Output is correct
51 Correct 136 ms 4952 KB Output is correct
52 Correct 302 ms 4932 KB Output is correct
53 Correct 299 ms 4940 KB Output is correct
54 Correct 303 ms 4936 KB Output is correct
55 Correct 382 ms 5132 KB Output is correct
56 Correct 367 ms 5140 KB Output is correct
57 Correct 387 ms 5080 KB Output is correct
58 Correct 382 ms 4932 KB Output is correct
59 Correct 350 ms 5144 KB Output is correct
60 Correct 301 ms 4952 KB Output is correct
61 Correct 340 ms 4952 KB Output is correct
62 Correct 373 ms 5112 KB Output is correct
63 Correct 333 ms 4952 KB Output is correct
64 Correct 453 ms 4936 KB Output is correct
65 Correct 463 ms 4944 KB Output is correct
66 Correct 447 ms 5112 KB Output is correct
67 Correct 466 ms 4952 KB Output is correct
68 Execution timed out 4061 ms 4928 KB Time limit exceeded
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4014 ms 4268 KB Time limit exceeded
2 Halted 0 ms 0 KB -