제출 #907614

#제출 시각아이디문제언어결과실행 시간메모리
907614vjudge1송신탑 (IOI22_towers)C++17
11 / 100
4051 ms5512 KiB
#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 max(a, b);}

    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, n) seg::init(i, H[i]);
}

int max_towers(int L, int R, int D) {
    // F(i, 0, 2*NN) seg::t[i].V = -1;
    vl dp(n+1, -1);

    ll res = 0;
    F(i, L, R+1) {
        ll ans = 1;
        {
            for (ll cur = i-1; cur >= L; cur--) if (h[cur] >= D + h[i]) ans = max(ans, dp[cur] + 1);
            // ll l = L, r = i+1;
            // while (l+1<r) {
            //     ll m = (l+r)/2;
            //     if (seg::query(m - 1, i).K >= D + h[i]) l = m;
            //     else r = m;
            // }
            // ans = max(ans, seg::query(l, i).V + 1);
            // cout << "Answer for " << i << ": " << seg::query(l, i).V + 1 << endl;
            // cout << "Reuqested " << l << " " << i << endl;
        }
        {
            // 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); 
            for (ll cur = i+1; cur <= R; cur++) if (h[cur] >= D + h[i]) dp[cur] = max(dp[cur], ans);

            // cout << "Placement for dp " << i << ": " << r << endl;
        }
        res = max(res, ans);
        // cout << "WTF " << i << endl;
        // F(i, L, R+1) cout << dp[i] << " "; cout << endl;
    }
    return res;


}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...