(mathcal{A})
for (int j = 2; j <= m; ++j) {
for (int i = 1; i <= n; ++i)
g[i] = f[i];
int top = 0, k = 0;
for (int i = j - 1; i <= n; ++i) {
while (k < top && s[k + 1].y - s[k].y <= a[i] * (s[k + 1].x - s[k].x)) ++k;
f[i] = a[i] * s[k].x - s[k].y;
Vec u = Vec(a[i], a[i] * a[i] - g[i]);
while (top > k && cross(u - s[top - 1], s[top] - s[top - 1]) >= 0) --top;
s[++top] = u;
}
}
下面的慢很多
for (int j = 2; j <= m; ++j) {
int top = 0, k = 0;
for (int i = j - 1; i <= n; ++i) {
while (k < top && s[k + 1].y - s[k].y <= a[i] * (s[k + 1].x - s[k].x)) ++k;
dp[i][j] = a[i] * s[k].x - s[k].y;
Vec u = Vec(a[i], a[i] * a[i] - dp[i][j - 1]);
while (top > k && cross(u - s[top - 1], s[top] - s[top - 1]) >= 0) --top;
s[++top] = u;
}
}
(mathcal{B})
typedef long long ll
ll x = 1e18 + 1
ll y = (ll)1e18 + 1
x还是1000000000000000000,y是1000000000000000001