Submission #235905

#TimeUsernameProblemLanguageResultExecution timeMemory
235905dlwocks31Split the sequence (APIO14_sequence)C++17
100 / 100
394 ms84216 KiB
#include <bits/stdc++.h> #define MAXN 100005 using namespace std; typedef long long ll; typedef pair<ll,int> pli; typedef vector<int> vi; typedef struct CHT{ ll la[MAXN], lb[MAXN]; int lz[MAXN]; int stkn=0,pt=1; void insert(ll a, ll b, int z){ while(stkn>pt){ if(a==la[stkn] && b>=lb[stkn]) stkn--; else if((lb[stkn]-b)*(la[stkn]-la[stkn-1])<(a-la[stkn])*(lb[stkn-1]-lb[stkn])) stkn--; else break; } if(a==la[stkn] && b>=lb[stkn] && z!=0) return; la[++stkn]=a; lb[stkn]=b; lz[stkn]=z; } pli query(ll x){ while(pt<stkn && (lb[pt]-lb[pt+1])<(la[pt+1]-la[pt])*x) pt++; return make_pair(la[pt]*x+lb[pt],lz[pt]); } }CHT; ll a[MAXN],D[2][MAXN],S[MAXN]; int pre[205][MAXN]; int main(){ int n,k; scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) scanf("%lld",&a[i]), S[i]=S[i-1]+a[i]; for(int i=1;i<=k;i++){ CHT c; c.insert(0,0,0); for(int j=1;j<=n;j++){ pli temp=c.query(S[j]); D[i%2][j]=temp.first; pre[i][j]=temp.second; c.insert(S[j],D[(i-1)%2][j]-S[j]*S[j],j); } } printf("%lld\n",D[k%2][n]); int here=n; vi ans; ans.push_back(-1); for(int i=1;i<=k;i++){ ans.push_back(pre[k-i+1][here]); here=pre[k-i+1][here]; } sort(ans.begin(),ans.end()); for(int i=1;i<=k;i++){ if(ans[i]==0) ans[i]=1; if(ans[i]<=ans[i-1]) ans[i]=ans[i-1]+1; printf("%d ",ans[i]); } return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
sequence.cpp:35:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%lld",&a[i]), S[i]=S[i-1]+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...
#Verdict Execution timeMemoryGrader output
Fetching results...