Submission #798699

#TimeUsernameProblemLanguageResultExecution timeMemory
798699AlkaratBigger segments (IZhO19_segments)C++14
100 / 100
66 ms13016 KiB
#include <bits/stdc++.h> #define ll long long #define f first #define s second const int N=5e5+10; using namespace std; int n,pre[N],dp[N]; ll a[N]; 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]; a[i]+=a[i-1]; } for(int i=1; i<=n; i++) { pre[i]=max(pre[i],pre[i-1]); dp[i]=dp[pre[i]]+1; ll val=a[i]-a[pre[i]]; int nxt=lower_bound(a+1,a+n+1,val+a[i])-a; pre[nxt]=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...