为什么用unordered_multiset会TLE?
查看原帖
为什么用unordered_multiset会TLE?
319478
zhibuba楼主2020/7/27 16:44
#include <iostream>
#include <unordered_set>

using namespace std;

unordered_multiset<int> S;

inline int C2(int x)
{
    return x * (x - 1) / 2;
}

int main()
{
    cin.sync_with_stdio(false);
    int n, a, M = 0;
    cin >> n;
    while (n--)
        cin >> a, S.insert(a), M = max(M, a);
    long long ans = 0;
    for (int i = 1; i < M; i++)
    {
        for (int j = i; j <= M - i; j++)
        if (i != j)
            ans += S.count(i) * S.count(j) * C2(S.count(i + j));
        else
            ans += C2(S.count(i)) * C2(S.count(i * 2));
        ans %= 1000000007; 
    }
    cout << ans << flush;
    return 0;
}
2020/7/27 16:44
加载中...