제출 #265542

#제출 시각아이디문제언어결과실행 시간메모리
265542SegtreeBigger segments (IZhO19_segments)C++14
100 / 100
88 ms28884 KiB
#include<iostream> #include<algorithm> #include<vector> #include<fstream> using namespace std; typedef long long ll; typedef pair<ll,ll> P; #define rep(i,n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() #define chmin(a,b) a=min(a,b) #define chmax(a,b) a=max(a,b) #define N 500010 ll n,a[N],s[N]; ll dp[N],dq[N]; int main(){ cin.tie(0); ios::sync_with_stdio(0); cin>>n; rep(i,n)cin>>a[i]; s[0]=0; rep(i,n)s[i+1]=s[i]+a[i]; rep(i,n+1)dp[i]=1e18; dp[0]=0; dq[0]=0; //for(int k=1;k<=n;k++){ vector<ll> score,place; //scoreは単調増加 for(int i=0;i<=n;i++){ ll l=-1,r=score.size(),mid; while(l<r-1){ mid=(l+r)>>1; if(s[i]>=score[mid])l=mid; else r=mid; } if(l>=0){ dp[i]=s[i]-s[place[l]]; dq[i]=dq[place[l]]+1; } ll sc=dp[i]+s[i]; while(score.size()>0){ if(score.back()>=sc){ score.pop_back(); place.pop_back(); } else break; } score.push_back(sc); place.push_back(i); } //} cout<<dq[n]<<endl; }
#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...