BZOJ 1911 特别行动队

裸的斜率优化,去年的APIO怎么有此等水题。

//By YY_More
#include<cstdio>
struct point{
  long long x,y;
} now,D[1000010];  
long long sum[1000010];     
int L,R,n,a,b,c;
inline long long xmul(point p,point q,point s){
       return (q.x-p.x)*(s.y-p.y)-(q.y-p.y)*(s.x-p.x);
}       
int main(){
    scanf("%d",&n);
    scanf("%d%d%d",&a,&b,&c);
    for (int i=1;i<=n;i++){
        scanf("%d",&sum[i]);
        sum[i]+=sum[i-1];
        }    
    L=R=0;D[0].x=0;D[0].y=0;
    for (int i=1;i<=n;i++){
        while (L<R&&D[L].y-(2*a*sum[i]+b)*D[L].x<=D[L+1].y-(2*a*sum[i]+b)*D[L+1].x) L++;
        now.x=sum[i];now.y=D[L].y-(2*a*sum[i]+b)*D[L].x+2*a*sum[i]*sum[i]+b*sum[i]+c;
        while (L<R&&xmul(D[R-1],D[R],now)>=0) R--;
        D[++R]=now;
    }
    printf("%lld\n",D[R].y-a*sum[n]*sum[n]);
    return 0;
}
posted on 2011-07-30 20:30  YY_More 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/yymore/archive/2011/07/30/2122170.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值