#abc295e. E - Kth Number
E - Kth Number
Score : points
问题描述
我们有一个长度为 的整数序列,其中的整数介于 和 (包含两端)之间:。
Snuke 将按照以下顺序执行操作 1 和 2。
- 对于每个满足 的 ,独立地从 到 (包含两端)中均匀随机选择一个整数,并用该整数替换 。
- 将序列 按升序排序。
计算并输出经过这两个操作后 的期望值,结果对 取模。
如何打印模 的数?可以证明所求期望值总是有理数。此外,在本题的约束条件下,若将该期望值表示为两个互质整数 和 的形式 ,可以证明存在唯一的整数 ,满足 且 。请打印这个 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We have a sequence of length consisting of integers between and , inclusive: .
Snuke will perform the following operations 1 and 2 in order.
- For each such that , independently choose a uniform random integer between and , inclusive, and replace with that integer.
- Sort in ascending order.
Print the expected value of after the two operations, modulo .
How to print a number modulo ? It can be proved that the sought expected value is always rational. Additionally, under the Constraints of this problem, when that value is represented as using two coprime integers and , it can be proved that there is a unique integer such that and . Print this .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the expected value of after the two operations, modulo .
Sample Input 1
3 5 2
2 0 4
Sample Output 1
3
In the operation 1, Snuke will replace with an integer between and . Let be this integer.
- If or , we will have after the two operations.
- If , we will have after the two operations.
- If or , we will have after the two operations.
Thus, the expected value of is .
Sample Input 2
2 3 1
0 0
Sample Output 2
221832080
The expected value is .
Sample Input 3
10 20 7
6 5 0 2 0 0 0 15 0 0
Sample Output 3
617586310
update @ 2024/3/10 12:16:29