bzoj 1911: [Apio2010]特别行动队

呃呃呃,和平方的有什么区别吗。。

 1 #include <bits/stdc++.h>
 2 #define LL long long
 3 #define lowbit(x) x&(-x)
 4 #define inf 0x3f3f3f3f
 5 #define eps 1e-5
 6 #define N 1000005
 7 using namespace std;
 8 inline int ra()
 9 {
10     int x=0,f=1; char ch=getchar();
11     while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
12     while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
13     return x*f;
14 }
15 LL sum[N],f[N];
16 int A,B,C,n,q[N];
17 double slope(int j, int k)
18 {
19     return (double)((f[j]+A*sum[j]*sum[j]-B*sum[j])-(f[k]+A*sum[k]*sum[k]-B*sum[k]))/(double)(2*A*(sum[j]-sum[k]));
20 }
21 int main(int argc, char const *argv[])
22 {
23     n=ra(); A=ra(); B=ra(); C=ra();
24     for (int i=1; i<=n; i++) sum[i]=sum[i-1]+ra();
25     int l=0,r=0;
26     for (int i=1; i<=n; i++)
27     {
28         while (l<r && slope(q[l+1],q[l])<=(double)sum[i]) l++;
29         int t=q[l];
30         f[i]=f[t]+A*(sum[i]-sum[t])*(sum[i]-sum[t])+B*(sum[i]-sum[t])+C;
31         while (l<r && slope(q[r],q[r-1])>=slope(i,q[r])) r--;
32         q[++r]=i;
33     }
34     cout<<f[n];
35     return 0;
36 }

 

posted @ 2017-03-08 21:03  ws_ccd  阅读(109)  评论(0编辑  收藏  举报