题意:
分析:
(不想打字所以放了张图片)
对于每个前n项和,可以用前缀和进行预处理求出,然后负数取模注意下就可以了。
代码:
#include<iostream> #include<algorithm> #include<stdio.h> #include<cstring> #include<deque> #define mem(a, x) memset(a, x, sizeof(a)) void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); } typedef long long ll; using namespace std; const int mod = 1e9+7; ll n,i,j,cnt; ll a[300005],w[300005],sum[300005]; ll summ[300005]; int main() { cin >> n; for(i=1;i<=n;i++){ cin >> a[i]; sum[i] = (sum[i-1] + a[i]) % mod; summ[i] = (summ[i-1] + sum[i]) % mod; } for(i=1;i<=n;i++){ cin >> w[i]; } for(i=1;i<=n;i++){ cnt = (cnt + w[i] * (mod + summ[n] - summ[n-i] - summ[i-1]) % mod) % mod; } cout<<cnt<<endl; }