bdfz_2024_summer/day2/U458258/U458258.md

60 lines
1021 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 平均数之和
## 题目描述
对于一个长度为 $n$ 的数组,有 $\frac{n \times (n + 1)}{2}$ 个连续子区间。对于子区间 $a[l\sim r]$,其平均值为
$$
\frac{a[l]+...+a[r]}{r-l+1}
$$
求数组的所有子区间的平均数之和,对 $P=10^9+7$ 取模。
* 模意义下的除法:如果需要计算 $a/b \pmod P$,可以使用 $a\times b^{P-2} \pmod P$ 实现
## 输入格式
第一行1个整数 $t$,代表数据组数
每组数据第1行一个正整数 $n$,表示数组长度
每组数据第2行 $n$ 个正整数 $a[1\sim n]$
## 输出格式
输出 $t$ 行每行1个整数代表答案
## 样例 #1
### 样例输入 #1
```
5
7
1 4 3 9 3 6 10
4
4 9 2 9
4
9 9 1 7
6
8 9 1 6 5 7
10
5 6 10 5 7 9 2 4 3 2
```
### 样例输出 #1
```
792857292
166666727
500000066
633333457
564286026
```
## 提示
对于 30% 的测试点,$1 \leq n \leq 100$
对于 70% 的测试点,$1 \leq n \leq 5000$
对于 100% 的测试点,$1\le t\le 10, 1 \leq n \leq 10^5, 1 \leq a[i] \leq 100$