见鬼了
查看原帖
见鬼了
482660
konyakest楼主2022/11/13 19:16
// Problem: P3195 [HNOI2008]玩具装箱
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3195
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define F(i,j,k) for (signed i=signed(j);i<=signed(k);i++)
#define endl '\n'
#define int long long
const int maxn=5e4+5;

int n,l;
double s[maxn],dp[maxn];
int q[maxn],head=1,tail=1;

double a(int i){return s[i]+i;}
double b(int j){return s[j]+j+l+1;}
double X(int j){return b(j);}
double Y(int j){return dp[j]+b(j)*b(j);}
double slope(int i,int j){return (Y(i)-Y(j))/(X(i)-X(j));}

signed main() { 
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>l;
	F(i,1,n) cin>>s[i],s[i]+=s[i-1];
	F(i,1,n){
		while(head<tail&&slope(q[head],q[head+1])<2*a(i)) head++;
		//dp[i]=dp[q[head]]+b(q[head])*b(q[head])-2.0*a(i)*b(q[head])+a(i)*a(i);
		//20pts
		//dp[i]=dp[q[head]]+(a(i)-b(q[head]))*(a(i)-b(q[head]));
		//AC
		while(head<tail&&slope(i,q[tail-1])<slope(q[tail-1],q[tail])) tail--;
		q[++tail]=i;
	}
	cout<<(long long)dp[n];
	return 0; 
}





有记录为证

20pts AC

2022/11/13 19:16
加载中...