區間權值 字首和

2021-08-28 16:57:01 字數 1298 閱讀 8704

時間限制:c/c++ 1秒,其他語言2秒

空間限制:c/c++ 1048576k,其他語言2097152k

64bit io format: %lld

小 bo 有 n 個正整數 a1..an,以及乙個權值序列 w1…wn,現在他定義

現在他想知道

你只需要輸出答案對 109+7 取模後的值

第一行乙個正整數 n

第二行 n 個正整數 a1..an

第三行 n 個正整數 w1..wn

輸出答案對 109+7 取模後的值
示例1

複製

3

1 1 1

1 1 1

複製

10
1≤ n≤ 3x 105

1≤ ai≤ 107

1≤ wi≤ 107

題解位址

#include#include#include#include#include#include#include#include#include#include//#define mod 998244353

#define inf 0x3f3f3f3f

#define eps 1e-6

using namespace std;

typedef long long ll;

const int mod=1e9+7;

const int maxn=3e5+10;

ll w[maxn];

ll a[maxn];

ll f[maxn];//a[i]的字首和

ll g[maxn];//g[i]的字首和

int main()

for(int i=1;i<=n;i++)

scanf("%lld",&w[i]);

g[0]=0;

for(int i=1;i<=n;i++)

g[i]=(f[i]+g[i-1])%mod;

ll ans=0;

for(int i=1;i<=n;i++)

ans=(ans+(g[n]-g[n-i]-g[i-1])*w[i]%mod)%mod;

printf("%lld\n",(ans+mod)%mod);

}

NC19798 區間權值 字首和

列舉w 根據長度的增加,其實相當於變成某一段區間能多加幾次 而到了最高點後又會下降,加的次數會變少,因此維護這個資料即可 includeusing namespace std typedef long long ll typedef pair pll const int n 3e5 10 const...

問題 G 區間權值

時間限制 1 sec 記憶體限制 128 mb 提交 112 解決 49 提交 狀態 討論版 命題人 admin 題目描述 小bo有n個正整數a1.an,以及乙個權值序列w1 wn,現在他定義 現在他想知道 你只需要輸出答案對109 7取模後的值 輸入第一行乙個正整數n 第二行n個正整數a1.an ...

Luogu P1351 聯合權值 字首和

求樹上距離為二的點對權積之最值 和。70pts 列舉每個點,bfs兩層求和求最值和和。100pts 列舉每個點,先統計所有可達節點的權值和,再列舉可達點求權值和 第二種做法較第一種的優化 a1 a2 a1 a3 a1 a4 a2 a1 a2 a3 a1 sum a1 a2 sum a2 好巧妙啊 要...