算法
sub1
枚举$3$条木棍编号,暴力判断是否等腰,时间复杂度$O(n^3)$
sub2
枚举腰和底的编号,记录这个腰有多少个,注意特判底和腰长度相同的情况,时间复杂度$O(n^2)$
sub3
直接输出$C_n^3$
sub4
枚举腰长$d$,不难发现底的长度为$[1,2d-1]$,记录前缀和即可,同样要特判底和腰长度相同的情况。时
间复杂度$O(n)$
C++ 代码
#include <iostream>
#define int long long
using namespace std;
const int N = 2e5 + 10, MOD = 998244353;
const int inv2 = (MOD + 1) / 2, inv3 = (MOD + 1) / 3, inv6 = inv2 * inv3 % MOD;
int a[N], tax[N], sum[N];
int mx, ans;
signed main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
tax[a[i]]++;
mx = max(mx, a[i]);
}
for (int i = 1; i <= mx; ++i) sum[i] = (sum[i - 1] + tax[i]) % MOD;
for (int i = 1; i <= mx; ++i) {
int x = tax[i];
if (x < 2) continue;
ans = (ans + x * (x - 1) / 2 % MOD * (sum[min(i * 2 - 1, mx)] - x) % MOD
+ x * (x - 1) % MOD * (x - 2) % MOD * inv6 % MOD) % MOD;
}
cout << ans << '\n';
return 0;
}