CF1418E.Expected Damage
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are playing a computer game. In this game, you have to fight n monsters.
To defend from monsters, you need a shield. Each shield has two parameters: its current durability a and its defence rating b. Each monster has only one parameter: its strength d.
When you fight a monster with strength d while having a shield with current durability a and defence b, there are three possible outcomes:
- if a=0, then you receive d damage;
- if a>0 and d≥b, you receive no damage, but the current durability of the shield decreases by 1;
- if a>0 and d<b, nothing happens.
The i-th monster has strength di, and you will fight each of the monsters exactly once, in some random order (all n! orders are equiprobable). You have to consider m different shields, the i-th shield has initial durability ai and defence rating bi. For each shield, calculate the expected amount of damage you will receive if you take this shield and fight the given n monsters in random order.
你正在玩一款电脑游戏。在这款游戏中,你需要与 n 只怪物战斗。
为了抵御怪物,你需要一面盾牌。每面盾牌有两个参数:当前耐久度 a 和防御等级 b。每只怪物只有一个参数:其力量值 d。
当你使用当前耐久度为 a、防御等级为 b 的盾牌与力量值为 d 的怪物战斗时,会出现以下三种可能的结果:
- 若 a=0,则你受到 d 点伤害;
- 若 a>0 且 d≥b,则你不受到任何伤害,但盾牌的当前耐久度减少 1;
- 若 a>0 且 d<b,则什么也不会发生。
第 i 只怪物的力量值为 di,你将恰好与每只怪物战斗一次,且战斗顺序是随机的(所有 n! 种排列等概率)。你共有 m 面不同的盾牌可供选择,其中第 i 面盾牌的初始耐久度为 ai、防御等级为 bi。对每面盾牌,请计算:若选用该盾牌,并以随机顺序与给定的 n 只怪物战斗,你所受伤害的期望值。
输入格式
The first line contains two integers n and m (1≤n,m≤2⋅105) — the number of monsters and the number of shields, respectively.
The second line contains n integers d1, d2, ..., dn (1≤di≤109), where di is the strength of the i-th monster.
Then m lines follow, the i-th of them contains two integers ai and bi (1≤ai≤n; 1≤bi≤109) — the description of the i-th shield.
第一行包含两个整数 n 和 m(1≤n,m≤2⋅105),分别表示怪物的数量和盾牌的数量。
第二行包含 n 个整数 d1, d2, ..., dn(1≤di≤109),其中 di 表示第 i 个怪物的强度。
接下来是 m 行,其中第 i 行包含两个整数 ai 和 bi(1≤ai≤n;1≤bi≤109),表示第 i 个盾牌的描述。
输出格式
Print m integers, where the i-th integer represents the expected damage you receive with the i-th shield as follows: it can be proven that, for each shield, the expected damage is an irreducible fraction yx, where y is coprime with 998244353. You have to print the value of x⋅y−1mod998244353, where y−1 is the inverse element for y (y⋅y−1mod998244353=1).
输出 m 个整数,其中第 i 个整数表示使用第 i 个护盾时你所受到的期望伤害。可以证明:对于每个护盾,其期望伤害均为一个既约分数 yx,其中 y 与 998244353 互质。你需要输出 x⋅y−1mod998244353 的值,其中 y−1 是 y 的模 998244353 乘法逆元(即满足 y⋅y−1mod998244353=1)。
输入输出样例
输入#1
3 2 1 3 1 2 1 1 2
输出#1
665496237 1
输入#2
3 3 4 2 6 3 1 1 2 2 3
输出#2
0 8 665496236
输入解题思路,AI测评打分。不知道怎么写?