题意
题意就是给出一个数列和一个权值数列,然后让你按照题目中给的那个式子进行运算,认真理解一下(其实是偷看了隔壁大佬的博客,大佬博客:传送门)帮n列出来就能看到规律解析
给出$f(l,r)=\sum_{i=l}^{r}{a_{i}}*w_{r-l+1}$,求解
当的时候
答案为
当的时候
答案为
由此递推就完事了
代码
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int N = 3e5 + 7; const ll MOD=1e9+7; ll a[N]; int main(void) { int n ; scanf("%d",&n); for (int i = 1; i <= n; ++i) { scanf("%lld",&a[i]); a[i] = (a[i] + a[i - 1]) % MOD; } ll ans = 0, sum = 0; ll w; for (int i = 1; i <= n; ++i) { scanf("%lld",&w); sum = (sum + a[n - i + 1] - a[i - 1] + MOD) % MOD; ans = (ans + sum * w) % MOD; } printf("%lld\n",ans); return 0; }