Submission #1134986

#TimeUsernameProblemLanguageResultExecution timeMemory
1134986poatBigger segments (IZhO19_segments)C++20
0 / 100
0 ms328 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define int long long // #define mkp make_pair #define txt freopen("kout.in", "r", stdin), freopen("kout.out", "w", stdout); const int N = 200100, K = 20; const int mod = 1e9 + 7; void solve() { int n; cin >> n; int arr[n]; for(auto &i : arr) cin >> i; int pref[n] = {arr[0]}; for(int i = 1; i < n; i++) pref[i] += pref[i - 1] + arr[i]; pair<int, int> dp[n + 5]; dp[0] = {1, arr[0]}; vector<pair<int, int>> vec; vec.push_back({dp[0].second, 0}); for(int i = 1; i < n; i++) { dp[i] = {dp[i - 1].first, dp[i - 1].second + arr[i]}; int l = -1, r = vec.size(); while(r - l > 1) { int m = (l + r) / 2; if(pref[i] - pref[vec[m].second] >= vec[m].first) l = m; else r = m; } if(l != -1) dp[i] = {dp[vec[l].second].first + 1, pref[i] - pref[vec[l].second]}; while(!vec.empty() && vec.back().first >= dp[i].second) vec.pop_back(); vec.push_back({dp[i].second, i}); } cout << dp[n - 1].first << '\n'; } signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int T = 1; for (; T--; 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...