0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-20 04:25:25 +00:00

P5686 [CSP-SJX2019]和积和

R43081842
This commit is contained in:
Baoshuo Ren 2020-12-03 13:14:59 +08:00 committed by Baoshuo Ren
parent 5feb80b868
commit 6ea0b00856
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

26
problem/P5686/P5686.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <bits/stdc++.h>
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;
}