Submission #1006269

#TimeUsernameProblemLanguageResultExecution timeMemory
1006269christinelynnBigger segments (IZhO19_segments)C++17
73 / 100
12 ms3676 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define fi first #define se second #define pb push_back #define pii pair<int,int> #define piii pair<pair<int,int>,pair<int,int>> int a[100005]; int pref[100005], dp[100005], bef[100005]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; pref[i] = pref[i-1] + a[i]; } a[n+1] = 1e18; int ans = 0; for(int i = 1; i <= n; i++){ bef[i] = max(bef[i], bef[i-1]); dp[i] = dp[bef[i]] + 1; ans = max(ans, dp[i]); int l = 1, r = n, ret = -1; while(l <= r){ int mid = (l+r)/2; if(pref[mid] >= (2 * pref[i]) - pref[bef[i]]){ r = mid - 1; ret = mid; } else{ l = mid + 1; } } bef[ret] = i; } cout << ans << endl; }
#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...