#abc332f. F - Random Update Query
F - Random Update Query
Score : points
问题描述
给定一个长度为 的整数序列 。
我们将按照以下顺序对 进行 次操作。
- 首先,随机均匀选择一个在 和 (包含两端点)之间的整数,并记作 。
- 然后,将 的值改为整数 。
对于上述过程结束后得到的最终序列 ,请分别计算并输出 (对于 )的期望值,取模 后的结果。
如何打印模 下的期望值
可以证明本题中所求的期望值始终是理性的。此外,本题的约束条件保证了如果每个期望值都表示为不可约分数 ,则 不会被 整除。
现在,存在一个唯一在 到 (包含两端点)之间的整数 ,满足 。请报告这个 值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given an integer sequence of length .
We will perform the following operation on for in this order.
- First, choose an integer between and , inclusive, uniformly at random and denote it as .
- Then, change the value of to the integer .
For the final sequence after the above procedure, print the expected value, modulo , of for each .
How to print expected values modulo
It can be proved that the expected values sought in this problem are always rational. Furthermore, the constraints of this problem guarantee that if each of those expected values is expressed as an irreducible fraction , then is not divisible by .
Now, there is a unique integer between and , inclusive, such that . Report this .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected values of the final for in the format below, separated by spaces.
Sample Input 1
5 2
3 1 4 1 5
1 2 2
2 4 0
Sample Output 1
499122179 1 665496238 665496236 5
We start from the initial state and perform the following two operations.
- The first operation chooses or uniformly at random, and changes its value to .
- Then, the second operation chooses one of uniformly at random, and changes its value to .
As a result, the expected values of the elements in the final are $(E_1, E_2, E_3, E_4, E_5) = (\frac{5}{2}, 1, \frac{8}{3}, \frac{2}{3}, 5)$.
Sample Input 2
2 4
1 2
1 1 3
2 2 4
1 1 5
2 2 6
Sample Output 2
5 6
Sample Input 3
20 20
998769066 273215338 827984962 78974225 994243956 791478211 891861897 680427073 993663022 219733184 570206440 43712322 66791680 164318676 209536492 137458233 289158777 461179891 612373851 330908158
12 18 769877494
9 13 689822685
6 13 180913148
2 16 525285434
2 14 98115570
14 17 622616620
8 12 476462455
13 17 872412050
14 15 564176146
7 13 143650548
2 5 180435257
4 10 82903366
1 2 643996562
8 10 262860196
10 14 624081934
11 13 581257775
9 19 381806138
3 12 427930466
6 19 18249485
14 19 682428942
Sample Output 3
821382814 987210378 819486592 142238362 447960587 678128197 687469071 405316549 318941070 457450677 426617745 712263899 939619994 228431878 307695685 196179692 241456697 12668393 685902422 330908158
update @ 2024/3/10 01:18:50