"Original question"
1911: [Apio2010] Special Action Team time limit: 4 Sec Memory Limit: MB
Submit: 2134 Solved: 911
[Submit] [Status] Descriptioninputoutputsample Input4
-1 10-20
2 2 3 4Sample Output9HINT
"Analysis" as long as I follow the topic ahead, this problem is really too water. God horse no reference, formula casually push.
The Ishi equation is F[i]=max (f[j]+a* (Sum[i]-sum[j]) ^2+b* (Sum[i]-sum[j]) +c)
Set K ratio J Excellent.
F[k]+a (Sum[i]-sum[k]) ^2+b (Sum[i]-sum[k]) +c>f[j]+a (Sum[i]-sum[j]) ^2+b (Sum[i]-sum[j]) +c
F[K]-2*A*SUM[I]*SUM[K]+A*SUM[K]^2-B*SUM[K]>F[J]-2*A*SUM[I]*SUM[J]+A*SUM[J]^2-B*SUM[J]
f[k]-f[j]+a* (sum[k]^2-sum[j]^2) +b* (Sum[j]-sum[k]) >2*a*sum[i]* (Sum[k]-sum[j])
(f[k]-f[j]+a* (sum[k]^2-sum[j]^2) +b* (Sum[j]-sum[k])/2/(Sum[k]-sum[j])/a<sum[i]
Code
#include <cstdio> #include <algorithm>using namespace Std;long long n,a[1000005],f[1000005],q[1000005], Sum[1000005],ans,h,t,i,a,b,c,j;long long M (long long x) {return x*x;} Double Xie (Long long K,long long j) { double temp= (f[k]-f[j]+a* (M (Sum[k])-M (Sum[j])) +b* (Sum[j]-sum[k]) +0.0)/2.0/( SUM[K]-SUM[J]/A; return temp;} int main () { scanf ("%lld", &n); scanf ("%lld%lld%lld", &a,&b,&c); for (i=1;i<=n;i++) scanf ("%lld", &a[i]), sum[i]=sum[i-1]+a[i]; f[0]=0;h=t=1ll;q[1]=0; for (i=1;i<=n;i++) { while (H<t&&xie (Q[h+1],q[h]) <=sum[i]) h++; F[i]=f[q[h]]+a*m (Sum[i]-sum[q[h]]) +b* (Sum[i]-sum[q[h]]) +c; while (H<t&&xie (Q[t],q[t-1]) >xie (i,q[t])) t--; q[++t]=i; } printf ("%lld", F[n]); return 0;}