标签:cer a long 误差 ges otto 转化 for col print
http://acm.hdu.edu.cn/showproblem.php?pid=3507
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
#include<cstdio> #include<cstring> #define N 500001 using namespace std; typedef long long LL; LL sum[N],dp[N]; int c,q[N],head,tail; long long up(int k,int j) { return dp[j]-dp[k]-sum[k]*sum[k]+sum[j]*sum[j]; } long long down(int k,int j) { return 2*(sum[j]-sum[k]); } int main() { int n,m,x; while(scanf("%d%d",&n,&m)!=EOF) { memset(sum,0,sizeof(sum)); for(int i=1;i<=n;i++) { scanf("%d",&x); sum[i]=sum[i-1]+x; } head=tail=0; memset(q,0,sizeof(q)); memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) { while(head<tail && up(q[head],q[head+1])<=sum[i]*down(q[head],q[head+1])) head++; dp[i]=dp[q[head]]+m+(sum[i]-sum[q[head]])*(sum[i]-sum[q[head]]); while(head<tail && up(q[tail-1],q[tail])*down(q[tail],i)>=up(q[tail],i)*down(q[tail-1],q[tail])) tail--; q[++tail]=i; } printf("%lld\n",dp[n]); } }
标签:cer a long 误差 ges otto 转化 for col print
原文地址:http://www.cnblogs.com/TheRoadToTheGold/p/7479606.html