Submission #907636

# Submission time Handle Problem Language Result Execution time Memory
907636 2024-01-16T00:59:39 Z vjudge1 Radio Towers (IOI22_towers) C++17
23 / 100
545 ms 8376 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);
    }
}

vector<pl> segs;

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

    F(i, 0, n) seg::init(i, H[i]);
    F(i, 0, n-1) if (h[i] < h[i+1]) {
        if (segs.size() and segs.back().V == i - 1) segs.back().V = i;
        else segs.emplace_back(i, i);
    }
}

/*
    4 1 2 3 5 1 2 3
      [   ]   [   ]

*/

int solved1(ll L, ll R) {
    if (L == R) return 1;
    ll extra = 0;
    if (h[R-1] > h[R]) extra++;
    ll ans = 0;

    auto it = upper_bound(A(segs), pl(L, -1));
    if (it != segs.begin()) --it;
    ans = lower_bound(A(segs), pl(R, -1)) - it;
    auto nxt = lower_bound(A(segs), pl(R, -1));
    if (nxt != segs.end() and nxt->K <= R and R <= nxt->V and extra) extra--;
    return ans + extra; 
}

int brute(int L, int R, int D) {

    F(i, 0, 2*NN) seg::t[i].V = -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;
}

int max_towers(int L, int R, int D) {
    static int calls = 0;
    if (calls++ > 1) 
    {
        // we are in special cases
        if (D == 1) {
            int ans = solved1(L, R);
            // int rans = brute(L, R, D);
            // cout << "QUERYING " << L << " " << R << endl;
            // cout << "WTF " << ans << " " << rans << endl;
            // cout << "YO?? IDEMPOTENCY<???? " << brute(L, R, D) << " " << brute(L, R, D) << endl;
            // assert(ans == rans);

            return ans;
        }

        assert(false);

        return -1;
    }
    // vl dp(n+1, -1);/
    return brute(L, R, D);
}
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 8376 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 3416 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 3412 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 3 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 3 ms 3416 KB Output is correct
17 Correct 2 ms 3416 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 3416 KB Output is correct
26 Correct 5 ms 3416 KB Output is correct
27 Correct 5 ms 3416 KB Output is correct
28 Correct 5 ms 3416 KB Output is correct
29 Correct 5 ms 3416 KB Output is correct
30 Correct 5 ms 3668 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 3416 KB Output is correct
34 Correct 6 ms 3416 KB Output is correct
35 Correct 5 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 3416 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 3412 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 3 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 3 ms 3416 KB Output is correct
17 Correct 2 ms 3416 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 3416 KB Output is correct
26 Correct 5 ms 3416 KB Output is correct
27 Correct 5 ms 3416 KB Output is correct
28 Correct 5 ms 3416 KB Output is correct
29 Correct 5 ms 3416 KB Output is correct
30 Correct 5 ms 3668 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 3416 KB Output is correct
34 Correct 6 ms 3416 KB Output is correct
35 Correct 5 ms 3416 KB Output is correct
36 Correct 56 ms 4796 KB Output is correct
37 Correct 146 ms 6052 KB Output is correct
38 Correct 59 ms 6076 KB Output is correct
39 Correct 137 ms 6088 KB Output is correct
40 Correct 55 ms 6052 KB Output is correct
41 Correct 311 ms 6080 KB Output is correct
42 Correct 27 ms 6068 KB Output is correct
43 Correct 220 ms 4944 KB Output is correct
44 Correct 65 ms 4932 KB Output is correct
45 Correct 30 ms 4932 KB Output is correct
46 Correct 26 ms 4928 KB Output is correct
47 Correct 105 ms 6084 KB Output is correct
48 Correct 68 ms 6076 KB Output is correct
49 Correct 38 ms 6076 KB Output is correct
50 Correct 83 ms 4948 KB Output is correct
51 Correct 136 ms 4936 KB Output is correct
52 Correct 307 ms 6052 KB Output is correct
53 Correct 307 ms 6180 KB Output is correct
54 Correct 299 ms 6080 KB Output is correct
55 Correct 377 ms 4932 KB Output is correct
56 Correct 361 ms 4936 KB Output is correct
57 Correct 384 ms 5564 KB Output is correct
58 Correct 381 ms 6068 KB Output is correct
59 Correct 349 ms 6224 KB Output is correct
60 Correct 298 ms 6072 KB Output is correct
61 Correct 341 ms 6068 KB Output is correct
62 Correct 370 ms 6088 KB Output is correct
63 Correct 345 ms 6084 KB Output is correct
64 Correct 451 ms 4936 KB Output is correct
65 Correct 472 ms 5032 KB Output is correct
66 Correct 441 ms 4936 KB Output is correct
67 Correct 463 ms 4932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 545 ms 6068 KB 4th lines differ - on the 1st token, expected: '13956', found: '13957'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 121 ms 8048 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 3416 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 3412 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 3 ms 3416 KB Output is correct
15 Correct 2 ms 3416 KB Output is correct
16 Correct 3 ms 3416 KB Output is correct
17 Correct 2 ms 3416 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 3416 KB Output is correct
26 Correct 5 ms 3416 KB Output is correct
27 Correct 5 ms 3416 KB Output is correct
28 Correct 5 ms 3416 KB Output is correct
29 Correct 5 ms 3416 KB Output is correct
30 Correct 5 ms 3668 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 3416 KB Output is correct
34 Correct 6 ms 3416 KB Output is correct
35 Correct 5 ms 3416 KB Output is correct
36 Correct 56 ms 4796 KB Output is correct
37 Correct 146 ms 6052 KB Output is correct
38 Correct 59 ms 6076 KB Output is correct
39 Correct 137 ms 6088 KB Output is correct
40 Correct 55 ms 6052 KB Output is correct
41 Correct 311 ms 6080 KB Output is correct
42 Correct 27 ms 6068 KB Output is correct
43 Correct 220 ms 4944 KB Output is correct
44 Correct 65 ms 4932 KB Output is correct
45 Correct 30 ms 4932 KB Output is correct
46 Correct 26 ms 4928 KB Output is correct
47 Correct 105 ms 6084 KB Output is correct
48 Correct 68 ms 6076 KB Output is correct
49 Correct 38 ms 6076 KB Output is correct
50 Correct 83 ms 4948 KB Output is correct
51 Correct 136 ms 4936 KB Output is correct
52 Correct 307 ms 6052 KB Output is correct
53 Correct 307 ms 6180 KB Output is correct
54 Correct 299 ms 6080 KB Output is correct
55 Correct 377 ms 4932 KB Output is correct
56 Correct 361 ms 4936 KB Output is correct
57 Correct 384 ms 5564 KB Output is correct
58 Correct 381 ms 6068 KB Output is correct
59 Correct 349 ms 6224 KB Output is correct
60 Correct 298 ms 6072 KB Output is correct
61 Correct 341 ms 6068 KB Output is correct
62 Correct 370 ms 6088 KB Output is correct
63 Correct 345 ms 6084 KB Output is correct
64 Correct 451 ms 4936 KB Output is correct
65 Correct 472 ms 5032 KB Output is correct
66 Correct 441 ms 4936 KB Output is correct
67 Correct 463 ms 4932 KB Output is correct
68 Incorrect 545 ms 6068 KB 4th lines differ - on the 1st token, expected: '13956', found: '13957'
69 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 8376 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -