全wa萌新求条
查看原帖
全wa萌新求条
325833
青莲武者良苦用心楼主2024/8/12 16:34
#include<bits/stdc++.h>
using namespace std;
int n,h=1,t=1;
long double f[50004],L,c[50004],pre[50004];
struct poin{
	long double x,y;
	int id;
}q[50004],tmp;
long double slop(poin a,poin b){
	return ((b.y-a.y)/(b.x-a.x));
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>L;
	L=L+1;
	for(int i=1;i<=n;++i){
		cin>>c[i];
		pre[i]=pre[i-1]+c[i];
		c[i]=(long double)i+pre[i];
	}
	for(int i=1;i<=n;++i){
		while(slop(q[h],q[h+1])<2*c[i]&&t>h) ++h;
		f[i]=f[q[h].id]+(c[i]-c[q[h].id]-L)*(c[i]-c[q[h].id]-L);
		tmp.x=c[i]+L,tmp.y=f[i]+(c[i]+L)*(c[i]+L),tmp.id=i;
		while(slop(q[t-1],q[t])>slop(tmp,q[t-1])&&t>h) --t;
		q[++t]=tmp;
	}
	cout<<(long long)f[n];
	return 0;
}
2024/8/12 16:34
加载中...