codeforces round#721c

Posted Tokarczuk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}

以上是关于codeforces round#721c的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #721 (Div. 2) AB思维,B2博弈,C题map

Codeforces Round #721 (Div. 2)

Codeforces Round #721 (Div. 2)- C.Sequence Pair Weight - 双重前缀和累加

Codeforces Round #721 (Div. 2) C. Sequence Pair Weight

Codeforces Round #721 (Div. 2) C. Sequence Pair Weight

Codeforces Round #721 (Div. 2) C. Sequence Pair Weight