逆向思维
void solve()
{
int n;
cin >> n;
int ans = 0;
for (int i = 1; i <= n; i++) ans += (1 + n - i + 1) * (n - i + 1) / 2;
map<int, int> p;
for (int i = 1; i <= n; i++)
{
int x;
cin >> x;
if (p[x])
{
ans -= (n - i + 1) * p[x];
}
p[x] = i;
}
cout << ans << '\n';
}