CF1842G.Tenzing and Random Operations

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yet another random problem.

Tenzing has an array aa of length nn and an integer vv.

Tenzing will perform the following operation mm times:

  1. Choose an integer ii such that 1≤i≤n1 \leq i \leq n uniformly at random.
  2. For all jj such that i≤j≤ni \leq j \leq n, set aj:=aj+va_j := a_j + v.

Tenzing wants to know the expected value of ∏i=1nai\prod_{i=1}^n a_i after performing the mm operations, modulo 109+710^9+7.

Formally, let M=109+7M = 10^9+7. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output the integer xx that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

又一道随机问题。

丹增有一个长度为 nn 的数组 aa 和一个整数 vv。

丹增将执行以下操作 mm 次:

  1. 均匀随机选择一个整数 ii,满足 1≤i≤n1 \leq i \leq n。
  2. 对所有满足 i≤j≤ni \leq j \leq n 的 jj,令 aj:=aj+va_j := a_j + v。

丹增想知道:执行 mm 次操作后,∏i=1nai\prod_{i=1}^n a_i 的期望值(对 109+710^9+7 取模)。

形式化地,令 M=109+7M = 10^9+7。可以证明答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,输出满足 0≤x<M0 \le x < M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入格式

The first line of input contains three integers nn, mm and vv (1≤n≤50001\leq n\leq 5000, 1≤m,v≤1091\leq m,v\leq 10^9).

The second line of input contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1091\leq a_i\leq 10^9).

输入的第一行包含三个整数 nn、mm 和 vv(1≤n≤50001\leq n\leq 5000,1≤m,v≤1091\leq m,v\leq 10^9)。

输入的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1091\leq a_i\leq 10^9)。

输出格式

Output the expected value of ∏i=1nai\prod_{i=1}^n a_i modulo 109+710^9+7.

输出 ∏i=1nai\prod_{i=1}^n a_i 的期望值对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#1

    2 2 5
    2 2

    输出#1

    84
  • 输入#2

    5 7 9
    9 9 8 2 4

    输出#2

    975544726

说明/提示

There are three types of aa after performing all the mm operations :

1. a1=2,a2=12a_1=2,a_2=12 with 14\frac{1}{4} probability.

2. a1=a2=12a_1=a_2=12 with 14\frac{1}{4} probability.

3. a1=7,a2=12a_1=7,a_2=12 with 12\frac{1}{2} probability.

So the expected value of a1⋅a2a_1\cdot a_2 is 14⋅(24+144)+12⋅84=84\frac{1}{4}\cdot (24+144) + \frac{1}{2}\cdot 84=84.

执行全部 mm 次操作后,aa 有以下三种情况:

  1. a1=2, a2=12a_1=2,\,a_2=12,概率为 14\frac{1}{4};
  2. a1=a2=12a_1=a_2=12,概率为 14\frac{1}{4};
  3. a1=7, a2=12a_1=7,\,a_2=12,概率为 12\frac{1}{2}。

因此,a1⋅a2a_1\cdot a_2 的期望值为

14⋅(24+144)+12⋅84=84.\frac{1}{4}\cdot (24+144) + \frac{1}{2}\cdot 84 = 84.

输入解题思路,AI测评打分。不知道怎么写?

首页