刷题真的有用,只要是做过了这个题就稳稳的啊
#include <iostream>
using namespace std;
typedef long long LL;
int last[200];
int main()
{
string s;
cin >> s;
int n = s.size();
s = ' ' + s;
LL ans = 0;
for (int i = 1; i <= n; i ++)
{
ans += (LL)(i - last[s[i]]) * (n - i + 1);
last[s[i]] = i;
}
cout << ans << endl;
return 0;
}