Submission #936713

#TimeUsernameProblemLanguageResultExecution timeMemory
936713AiperiiiBigger segments (IZhO19_segments)C++14
100 / 100
169 ms20932 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n; cin>>n; vector <int> a(n+1),p(n+1),ind(n+1),ans(n+1); for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)p[i]=p[i-1]+a[i]; for(int i=1;i<=n;i++){ ind[i]=max(ind[i],ind[i-1]); ans[i]=ans[ind[i]]+1; int cur=p[i]-p[ind[i]]; //cout<<ind[i]<<" "<<ans[ind[i]]<<" "<<ans[i]<<"\n"; int l=i,r=n; int p_ind=0; while(l<=r){ int md=(l+r)/2; if(p[md]-p[i]>=cur){ p_ind=md; r=md-1; } else l=md+1; } ind[p_ind]=i; } cout<<ans[n]<<"\n"; } /* 4 2 3 1 7 5 6 2 3 9 13 3 3 1 2 5 1 12 11 46 47 */
#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...