朴素转移好写 但是化简需要技巧 一开始暴力化简感觉比圆锥曲线还难搞
可以发现Sum[i]和i本身总是同时出现在式子中 合并为T[i] 把L 变为 L + 1能省去很多化简的繁琐步骤 化简完成后就没什么难度了
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int powAXN = 50000;
typedef long long LL;
int Q[powAXN+10];
LL S[powAXN+10], d[powAXN+10], A[powAXN+10], T[powAXN+10];
LL F, R, n, L;
LL pow(LL x)
{
return x * x;
}
double Slope(int i, int j)
{
return (d[i] + pow(T[i] + L) - d[j] - pow(T[j] + L)) / 2.0 / (T[i] - T[j]);
}
int main()
{
cin >> n >> L; L++;
for(int i = 1; i <= n; i++) {
cin >> S[i];
S[i] += S[i-1];
T[i] = S[i] + i;
}
F = R = Q[0] = 0;
Q[R++] = 0;
for(int i = 1; i <= n; i++)
{
while(F < R - 1 && Slope(Q[F+1], Q[F]) < T[i])
F++;
d[i] = d[Q[F]] + pow(T[i] - T[Q[F]] - L);
while(F < R - 1 && Slope(Q[R-1], Q[R-2]) > Slope(i, Q[R-1]))
R--;
Q[R++] = i;
}
cout << d[n];
}