Submission #628218

#TimeUsernameProblemLanguageResultExecution timeMemory
628218TheQuantiXRadio Towers (IOI22_towers)C++17
15 / 100
1047 ms3028 KiB
// Made by TheQuantiX #include <bits/stdc++.h> //#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,sse4.2,bmi,bmi2,lzcnt,popcnt") using namespace std; using ll = long long; constexpr ll MAXN = 1e5; constexpr ll MOD = 1000000007; constexpr ll INF = 1000000000000000000LL; int tt, n, q, m, k, x, y, a, b, c, d; vector<int> v; vector<int> tr; void build(ll x, ll l, ll r) { if (l == r) { tr[x] = v[l]; return; } ll mid = (l + r) / 2; build(2 * x + 1, l, mid); build(2 * x + 2, mid + 1, r); tr[x] = max(tr[2 * x + 1], tr[2 * x + 2]); } ll query(ll x, ll l, ll r, ll lt, ll rt) { if (rt < l || r < lt) { return -INF; } if (rt < lt) { return -INF; } if (l <= lt && rt <= r) { return tr[x]; } ll mid = (lt + rt) / 2; return max(query(2 * x + 1, l, r, lt, mid), query(2 * x + 2, l, r, mid + 1, rt)); } void init(int n1, vector<int> h) { n = n1; v = h; tr.resize(h.size() * 4); build(0, 0, n - 1); } int max_towers(int l, int r, int d) { if (n <= 2000) { vector<ll> dp(n, 1); for (int i = l; i <= r; i++) { for (int j = i + 2; j <= r; j++) { ll mx = query(0, i, j, 0, n - 1); if (mx - v[i] >= d && mx - v[j] >= d) { dp[j] = max(dp[j], dp[i] + 1); } } } // if (*max_element(dp.begin(), dp.end()) == 1) { // return 0; // } return *max_element(dp.begin(), dp.end()); } else { ll mx = query(0, l, r, 0, n - 1); if (mx - v[l] >= d && mx - v[r] >= d) { return 2; } return 1; } } //void solve() { // cin >> n >> q; // vector<int> v(n); // for (int i = 0; i < n; i++) { // cin >> v[i]; // } // init(n, v); // for (int i = 0; i < q; i++) { // cin >> a >> b >> c; // cout << max_towers(a, b, c) << endl; // } //} // //int main() { // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // cout << fixed; // cout << setprecision(10); // tt = 1; //// cin >> tt; // while (tt --> 0) { // solve(); // } //}
#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...