codeforces round#721c

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
const int N = 1e5 + 10;
 
ll a[N], b[N];
ll t[N];
int n;
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T -- )
    {
        cin >> n;
        //不要memeset每次memset会超时
        for(int i = 1; i <= n; i ++ )
        {
            cin >> a[i];
            b[i] = a[i];
            t[i] = 0;
        }
        sort(b + 1, b + n + 1);
        int m = unique(b + 1, b + n + 1) - b - 1;
        for(int i = 1; i <= n; i ++ ) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b;
        ll res = 0 ;
        for(int i = 1; i <= n; i ++ )
        {
            res += t[a[i]] * (n - i + 1);
            t[a[i]] += i;
        }
        cout << res << endl;
 
    }
    return 0;
}
posted @ 2021-05-21 21:46  Tokarczuk  阅读(39)  评论(0)    收藏  举报