From 6ea0b008560f57052e12f95138e020b9c7cecb66 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Thu, 3 Dec 2020 13:14:59 +0800 Subject: [PATCH] =?UTF-8?q?P5686=20[CSP-SJX2019]=E5=92=8C=E7=A7=AF?= =?UTF-8?q?=E5=92=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R43081842 --- problem/P5686/P5686.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 problem/P5686/P5686.cpp diff --git a/problem/P5686/P5686.cpp b/problem/P5686/P5686.cpp new file mode 100644 index 00000000..f416bcf7 --- /dev/null +++ b/problem/P5686/P5686.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +const int mod = 1000000007; +long long n, ans, a[500005], b[500005], sa[500005], sb[500005], q[500005], qa[500005], qb[500005]; + +int main() { + cin >> n; + for (int i = 1; i <= n; i++) { + cin >> a[i]; + sa[i] = (sa[i - 1] + a[i]) % mod; + qa[i] = (qa[i - 1] + sa[i]) % mod; + } + for (int i = 1; i <= n; i++) { + cin >> b[i]; + sb[i] = (sb[i - 1] + b[i]) % mod; + qb[i] = (qb[i - 1] + sb[i]) % mod; + q[i] = (q[i - 1] + sa[i] * sb[i] % mod) % mod; + } + for (int i = 1; i <= n; i++) { + ans = (ans + ((q[n] - q[i - 1] + mod) % mod) - (((qb[n] - qb[i - 1] + mod) % mod * sa[i - 1]) % mod) - (((qa[n] - qa[i - 1] + mod) % mod * sb[i - 1]) % mod) + (((n - i + 1) * ((sa[i - 1] * sb[i - 1]) % mod)) % mod) + mod) % mod; + } + cout << ans << endl; + return 0; +}