标签:name pac end code std clu cin using for
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
ll s[maxn],x[maxn],n,a,b,c,f[maxn],ss[maxn];
int q[maxn];
double slope(int l,int r) {
double tmp1 = f[r]-b*s[r]+a*ss[r]-f[l]+b*s[l]-a*ss[l];
double tmp2 = s[r]-s[l];
return tmp1/tmp2;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>a>>b>>c;
for(int i = 1;i<=n;++i) {
cin>>x[i];
s[i]=s[i-1]+x[i];
ss[i]=s[i]*s[i];
}
int l = 0,r=0;
for(int i = 1;i<=n;++i) {
while(l<r&&slope(q[l],q[l+1])>2*a*s[i]) ++l;
int j = q[l];
f[i]=f[j]+a*ss[i]-2*a*s[i]*s[j]+a*ss[j]+b*s[i]-b*s[j]+c;
while(l<r&&slope(q[r-1],q[r])<slope(q[r],i)) --r;
q[++r]=i;
}
cout<<f[n]<<endl;
return 0;
}
标签:name pac end code std clu cin using for
原文地址:https://www.cnblogs.com/Syameimaru/p/10284855.html