Submission #341887

#TimeUsernameProblemLanguageResultExecution timeMemory
341887katearimaBigger segments (IZhO19_segments)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> //#define int long long #define sum first #define ind second using namespace std; const int N=500005; int a[N],sums[N], oldS, n; int ans[N]; priority_queue<pair<int, int> , vector<pair<int, int>> , greater<pair<int, int>>> pq; main(){ cin>>n; for(int i=0; i<n; i++){ cin>>a[i]; } sums[0]=a[0]; for(int i=1; i<n; i++){ sums[i]=a[i]+sums[i-1]; } int sp=0; // starting point of segment for(int i=0; i<n; i++){ while(pq.size()!=0 && pq.top().sum <= sums[i]){ int j=pq.top().ind; if(ans[j]>ans[sp]) sp=j; if(ans[j]==ans[sp]) sp=max(j, sp); pq.pop(); } ans[i] = ans[sp]+1; pq.push(make_pair(2*sums[i]-sums[sp-1], i)); } cout<<ans[n-1]<<endl; }

Compilation message (stderr)

segments.cpp:10:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      |      ^
#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...