Submission #46615

#TimeUsernameProblemLanguageResultExecution timeMemory
46615dqhungdlSplit the sequence (APIO14_sequence)C++17
0 / 100
114 ms85052 KiB
#include <bits/stdc++.h> using namespace std; struct Data { int64_t a,b,id; }; typedef pair<int64_t,int64_t> ii; int64_t n,k,top,pointer,a[100005],f[100005],ff[100005]; int Trace[100005][205]; Data S[100005]; bool Check(Data x1,Data x2,Data x3) { ///Intersection(x1,x2)=(x1.b-x2.b)/(x2.a-x1.a) ///Intersection(x1,x3)=(x1.b-x3.b)/(x3.a-x1.a) return (x1.b-x3.b)*(x2.a-x1.a)<=(x1.b-x2.b)*(x3.a-x1.a); } void Update(int64_t x,int64_t y,int64_t id) { while(top>=2&&Check(S[top-1],S[top],{x,y,id})==true) top--; S[++top]={x,y,id}; } ii Query(int64_t x) { pointer=min(pointer,top); while(pointer<top&&S[pointer+1].a*x+S[pointer+1].b<=S[pointer].a*x+S[pointer].b) pointer++; return ii(S[pointer].a*x+S[pointer].b,S[pointer].id); } void Process(int64_t kk) { top=0; pointer=1; Update(0,0,0); for(int64_t i=1;i<=n;i++) { ii tmp=Query(a[i]); ff[i]=-tmp.first; Trace[i][kk]=tmp.second; Update(-a[i],a[i]*a[i]-f[i],i); } for(int64_t i=1;i<=n;i++) f[i]=ff[i]; } int main() { ios_base::sync_with_stdio(false); //freopen("TEST.INP","r",stdin); scanf("%d%d",&n,&k); for(int64_t i=1;i<=n;i++) { scanf("%I64d",&a[i]); a[i]+=a[i-1]; } for(int64_t i=1;i<=k;i++) Process(i); printf("%d\n",f[n]); while(k>0) { n=Trace[n][k]; k--; printf("%d ",n); } }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:56:23: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'int64_t* {aka long int*}' [-Wformat=]
     scanf("%d%d",&n,&k);
                  ~~   ^
sequence.cpp:56:23: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'int64_t* {aka long int*}' [-Wformat=]
sequence.cpp:59:28: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'int64_t* {aka long int*}' [-Wformat=]
         scanf("%I64d",&a[i]);
                       ~~~~~^
sequence.cpp:64:23: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int64_t {aka long int}' [-Wformat=]
     printf("%d\n",f[n]);
                   ~~~~^
sequence.cpp:69:23: warning: format '%d' expects argument of type 'int', but argument 2 has type 'int64_t {aka long int}' [-Wformat=]
         printf("%d ",n);
                       ^
sequence.cpp:56: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:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%I64d",&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...