Submission #180307

#TimeUsernameProblemLanguageResultExecution timeMemory
180307rzbtBigger segments (IZhO19_segments)C++14
100 / 100
281 ms53240 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 500005 typedef long long ll; using namespace std; ll n; ll mz=0; ll tz=0; ll niz[MAXN]; pair<ll,ll> dp[MAXN]; ll pref[MAXN]; ll res[MAXN]; set<pair<ll,ll> > s; int main() { scanf("%lld", &n); for(ll i=1;i<=n;i++){ scanf("%lld",niz+i); pref[i]=pref[i-1]+niz[i]; } //dp[i]=mp(pref[i],1); ll dokle=0; for(ll i=1;i<=n;i++){ //if(!s.empty())printf(" %d %d\n") while(!s.empty() && s.begin()->F<=pref[i]){ dokle=max(dokle,s.begin()->S); s.erase(s.begin()); } //printf("%lld %lld\n",i,dokle); dp[i]=mp(pref[i]-pref[dokle],res[dokle]+1); res[i]=max(res[i-1],dp[i].S); s.insert(mp(dp[i].F+pref[i],i)); } printf("%lld",res[n]); return 0; }

Compilation message (stderr)

segments.cpp: In function 'int main()':
segments.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &n);
     ~~~~~^~~~~~~~~~~~
segments.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",niz+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...