Submission #288661

#TimeUsernameProblemLanguageResultExecution timeMemory
288661AMO5Bigger segments (IZhO19_segments)C++17
100 / 100
71 ms16440 KiB
//modified from errorgorn's solution #include <bits/stdc++.h> using namespace std; #define ll long long #define sz(x) (int)x.size() #define fi first #define se second const int mxn = 5e5+5; int n,cnt[mxn]; ll a[mxn]; 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]; } deque<pair<ll,int>>dq; dq.emplace_back(0ll,0); //expected sum , ind for(int i=1; i<=n; i++){ while(sz(dq)>=2&&dq[1].fi<=a[i])dq.pop_front(); cnt[i]=cnt[dq.front().se]+1; pair<ll,int>cur=pair<ll,int>(2*a[i]-a[dq.front().se],i); while(dq.back().fi>=cur.fi)dq.pop_back(); dq.emplace_back(cur); } cout<<cnt[n]<<"\n"; return 0; }
#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...