Submission #201389

#TimeUsernameProblemLanguageResultExecution timeMemory
201389guangxuanBigger segments (IZhO19_segments)C++14
100 / 100
162 ms15324 KiB
#include <bits/stdc++.h> using namespace std; int a[500009]; long long rs[500009]; int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&a[i]); rs[i+1]=rs[i]+a[i]; } pair<int,int> res = {0,0}; pair<int,long long> dp; priority_queue<pair<long long,pair<int,int> >,vector<pair<long long,pair<int,int> > >, greater< pair<long long,pair<int,int> > > > updates; for(int i=1;i<=n;i++){ while(updates.size() && updates.top().first<=rs[i]){ pair<int,int> cur = updates.top().second; updates.pop(); res = max(res,cur); } dp = {res.first,rs[res.second] - rs[i]}; dp.first++; updates.push({rs[i]-dp.second,{dp.first,i}}); //cout << dp[i].first << ' ' << dp[i].second << '\n'; // cout << res.first << ' ' << res.second.first << ' ' << res.second.second << '\n'; } printf("%d", dp.first); }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
segments.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
#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...