0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 18:38:47 +00:00

P3799 妖梦拼木棒

R55412792
This commit is contained in:
Baoshuo Ren 2021-08-09 21:14:30 +08:00 committed by Baoshuo Ren
parent a503db7bf7
commit 0895f652d6
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, maxa, a[100005], num[100005];
long long ans;
long long C(long long x, long long k) {
return (k == 1ll ? x : x * (x - 1ll) / 2ll) % mod;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
maxa = max(maxa, a[i]);
num[a[i]]++;
}
for (int i = 0; i < n; i++) {
if (num[i] >= 2ll) {
long long times = C(num[i], 2ll) % mod;
for (int j = 1; j <= i / 2; ++j) {
if (j != i - j && num[j] >= 1 && num[i - j] >= 1) {
ans += times * C(num[j], 1) * C(num[i - j], 1) % mod;
}
if (j == i - j && num[j] >= 2) {
ans += times * C(num[j], 2) % mod;
}
ans %= mod;
}
}
}
cout << ans << endl;
return 0;
}