Submission #860994

#TimeUsernameProblemLanguageResultExecution timeMemory
860994CookieBigger segments (IZhO19_segments)C++14
100 / 100
86 ms48152 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ll long long #define vt vector #define pb push_back #define pii pair<int, int> #define sz(dq) (int)dq.size() #define forr(i, a, b) for(int i = a; i < b; i++) #define fi first #define se second #define pll pair<ll, ll> ifstream fin("store.inp"); ofstream fout("store.out"); const ll mxn = 5e5 + 5, inf = 1e9, mod = 1e9 + 7, sq = 800, mxv = 1e6 + 5, pr = 37, mod2 = 1e9 + 9, mod3 = 998244353; //const int x[4] = {0, -1, 0, 1}; int n; pll dp[mxn + 1]; ll a[mxn + 1], pref[mxn + 1]; vt<pll>events[mxn + 1]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } dp[0] = make_pair(0, 0); pair<ll, ll>mx = make_pair(0, 0); for(int i = 1; i <= n; i++){ for(auto j: events[i]){ mx = max(mx, j); } dp[i] = make_pair(mx.first + 1, pref[i] - pref[mx.second]); int l = i + 1, r = n, ans = n + 1; while(l <= r){ int mid = (l + r) >> 1; if(pref[mid] - pref[i] >= pref[i] - pref[mx.second]){ ans = mid; r = mid - 1; }else{ l = mid + 1; } } events[ans].pb(make_pair(dp[i].first, i)); } cout << dp[n].first; return(0); }
#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...