Submission #907622

# Submission time Handle Problem Language Result Execution time Memory
907622 2024-01-16T00:29:51 Z vjudge1 Radio Towers (IOI22_towers) C++17
0 / 100
4000 ms 6472 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);
    }
}

ll pfsum[NN], a[NN];

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]);
    F(i, 0, n) {
        bool peak = 1;
        if (i > 0) peak &= H[i] > H[i-1];
        if (i + 1 != n) peak &= H[i] > H[i+1];
        if (peak) {
            if (i > 0) a[i-1]=1;
            if (i + 1 != n) a[i+1]=1; 
        }
    }
    F(i, 0, n) pfsum[i+1] = pfsum[i] + a[i];
}

int solved1(int L, int R) {
    int D = 1;
    return pfsum[R+1] - pfsum[L];
}

int max_towers(int L, int R, int D) {
    if (D == 1) return solved1(L, R);

    // 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;


}

Compilation message

towers.cpp: In function 'int solved1(int, int)':
towers.cpp:78:9: warning: unused variable 'D' [-Wunused-variable]
   78 |     int D = 1;
      |         ^
# Verdict Execution time Memory Grader output
1 Execution timed out 4034 ms 5804 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4828 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4828 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 416 ms 6472 KB 1st lines differ - on the 1st token, expected: '11903', found: '19112'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4030 ms 5396 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 3 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 3 ms 4952 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4828 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Incorrect 2 ms 4952 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4034 ms 5804 KB Time limit exceeded
2 Halted 0 ms 0 KB -