Submission #1241876

#TimeUsernameProblemLanguageResultExecution timeMemory
1241876AMel0nBouquet (EGOI24_bouquet)C++20
0 / 100
59 ms26948 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i,N) for(ll i = 0; i < N; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second ll N; vector<ll> tree; void update(ll v, ll p, ll tl = 0, ll tr = N-1, ll i = 1) { if (tl == tr) {tree[i] = min(tree[i], v); return ;} ll tm = (tl + tr) / 2; if (p <= tm) update(v, p, tl, tm, i * 2); else update(v, p, tm + 1, tr, i * 2 + 1); tree[i] = max(tree[i * 2], tree[i * 2 + 1]); } ll walk(ll x, ll tl = 0, ll tr = N-1, ll i = 1) { if (tl == tr) return tl - 1; ll tm = (tl + tr) / 2; if (tree[i * 2] >= x) return walk(x, tl, tm, i * 2); else return walk(x, tm + 1, tr, i * 2 + 1); } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; vector<ll> L(N), R(N); FOR(i, N) cin >> L[i] >> R[i]; vector<vector<ll>> todo(N*2+5); vector<ll> dp(N); tree.resize(4*(N+5), 1e18); // tree[tl] = max j such that dp[j] > tl dp[0] = 1; update(-1, 0); todo[R[0] + 1].push_back(0); for(ll i = 1; i < N; i++) { for(ll j: todo[i]) update(j, dp[j]); dp[i] = 1 + walk(i - L[i]); todo[i + R[i] + 1].push_back(i); } cout << *max_element(all(dp)); }
#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...