ans
2025-10-27 15:15:23
发布于:日本
10阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll comb3(ll x){
if (x < 3) return 0;
return x*(x-1)(x-2)/6;
}
ll comb2(ll x){
if (x < 2) return 0;
return x(x-1)/2;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
if (!(cin >> n)) return 0;
vector<long long> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end())
vector<pair<long long int>> vals;
for (int i = 0; i < n; ){
int j = i;
while (j < n && a[j] == a[i]) ++j;
vals.push_back({a[i], j - i});
i = j;
}
int U = vals.size();
long long ans = 0;
for (int i = 0; i < U; ++i) {
ans += comb3(vals[i].second);
}
for (int i = 0; i < U; ++i) {
ll x = vals[i].first;
ll fx = vals[i].second;
if (fx < 2) continue;
ll chooseXX = comb2(fx); // C(fx,2)
for (int j = 0; j < U; ++j) {
if (i == j) continue;
ll y = vals[j].first;
ll fy = vals[j].second;
if (2 * x > y) {
ans += chooseXX * fy;
}
}
}
cout << ans << "\n";
return 0;
}
这里空空如也



有帮助,赞一个