From 0895f652d6e7034e789f3559c35b121ebbe1df5c Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Mon, 9 Aug 2021 21:14:30 +0800 Subject: [PATCH] =?UTF-8?q?P3799=20=E5=A6=96=E6=A2=A6=E6=8B=BC=E6=9C=A8?= =?UTF-8?q?=E6=A3=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R55412792 --- Luogu/problem/P3799/P3799.cpp | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Luogu/problem/P3799/P3799.cpp diff --git a/Luogu/problem/P3799/P3799.cpp b/Luogu/problem/P3799/P3799.cpp new file mode 100644 index 00000000..f7aac53c --- /dev/null +++ b/Luogu/problem/P3799/P3799.cpp @@ -0,0 +1,37 @@ +#include + +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; +}