Submission #341164

#TimeUsernameProblemLanguageResultExecution timeMemory
341164Dilshod_ImomovBigger segments (IZhO19_segments)C++17
100 / 100
85 ms20844 KiB
# include <bits/stdc++.h> # define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) # define int long long # define fi first # define se second using namespace std; const int N = 5e5 + 7; const int mod = 1e9 + 7; int a[N], sum[N], dp[N], ind[N]; int32_t main() { speed; int n; cin >> n; for ( int i = 1; i <= n; i++ ) { cin >> a[i]; sum[i] = sum[i - 1] + a[i]; } for ( int i = 1; i <= n; i++ ) { ind[i] = max( ind[i - 1], ind[i] ); dp[i] = dp[ ind[i] ] + 1; int l = i + 1, r = n, ans = n + 1; while ( l <= r ) { int m = (l + r) / 2; if ( sum[m] - sum[i] >= sum[i] - sum[ ind[i] ] ) { ans = m; r = m - 1; } else { l = m + 1; } } // cout << i << ' ' << dp[i] << ' ' << ans << endl; ind[ans] = i; } cout << dp[n]; }
#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...