感受
思路
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; const int maxn = 3e5 + 10; int n; ll sum[maxn], suf[maxn], a[maxn], w[maxn], dp[maxn]; int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%lld", &a[i]); sum[i] = sum[i - 1] + a[i]; } for(int i = n; i >= 1; i--){ suf[i] = suf[i + 1] + a[i]; } for(int i = 1; i <= n; i++){ scanf("%lld", &w[i]); } ll ans = 0; for(int i = 1; i <= n; i++){ dp[i] = dp[i - 1] - suf[n - i + 2] + sum[n] - sum[i - 1]; dp[i] %= mod; while(dp[i] < 0) dp[i] += mod; ans = ans + w[i] * dp[i] % mod; ans %= mod; } printf("%lld\n", ans); return 0; }