给个hack数据吧...球球了..调不出来了
#include <bits/stdc++.h>
#define int long long
#define maxn 100005
using namespace std;
int n, col[maxn], c[maxn], f[maxn], t[maxn], L[maxn], R[maxn], Q[10005][1005], first[maxn];
double Y(int x) {
return (double)(f[x - 1] + col[x] * c[x] * c[x] - 2 * col[x] * c[x]);
}
double X(int x) {
return (double)c[x];
}
double slope(int x, int y) {
if(x == 0 || y == 0) return 0;
return (double) (Y(y) - Y(x)) / (X(y) - X(x));
}
signed main() {
scanf("%lld", &n);
for(int i = 1;i <= n;i++) {
scanf("%lld", &col[i]);
c[i] = ++ t[col[i]];
}
for(int i = 1;i <= 100000;i++) L[i] = 1, R[i] = 0;
for(int i = 1;i <= n;i++) {
int t = col[i];
Q[t][++ R[t]] = i;
// cout << slope(Q[t][L[t]], Q[t][L[t] + 1]) << " " << Q[t][L[t]] << " " << Q[t][L[t] + 1] << " " << L[t] <<" " << R[t] <<endl;
while(L[t] <= R[t] && slope(Q[t][L[t]], Q[t][L[t] + 1]) > 2 * t * c[i]) L[t] ++;
f[i] = max(f[i], f[Q[t][L[t]] - 1] + t * (c[i] - c[Q[t][L[t]]] + 1) * (c[i] - c[Q[t][L[t]]] + 1));
// cout << f[Q[t][L[t]] - 1] << " " << Q[t][L[t]] << " " << t << " " << c[i] <<" " << c[Q[t][L[t]]] << endl;
while(L[t] <= R[t] && slope(Q[t][R[t] - 1], Q[t][R[t]]) > slope(Q[t][R[t]], i)) R[t] --;
// cout << f[i] << " " <<Q[t][L[t]] <<endl;
}
cout << f[n] << endl;
}
/*
10
1 5 4 2 3 3 4 2 5 1
10
1 2 3 4 3 2 1 5 3 5
*/