CF1418E.Expected Damage

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are playing a computer game. In this game, you have to fight nn monsters.

To defend from monsters, you need a shield. Each shield has two parameters: its current durability aa and its defence rating bb. Each monster has only one parameter: its strength dd.

When you fight a monster with strength dd while having a shield with current durability aa and defence bb, there are three possible outcomes:

  • if a=0a = 0, then you receive dd damage;
  • if a>0a \gt 0 and d≥bd \ge b, you receive no damage, but the current durability of the shield decreases by 11;
  • if a>0a \gt 0 and d<bd \lt b, nothing happens.

The ii-th monster has strength did_i, and you will fight each of the monsters exactly once, in some random order (all n!n! orders are equiprobable). You have to consider mm different shields, the ii-th shield has initial durability aia_i and defence rating bib_i. For each shield, calculate the expected amount of damage you will receive if you take this shield and fight the given nn monsters in random order.

你正在玩一款电脑游戏。在这款游戏中,你需要与 nn 只怪物战斗。

为了抵御怪物,你需要一面盾牌。每面盾牌有两个参数:当前耐久度 aa 和防御等级 bb。每只怪物只有一个参数:其力量值 dd。

当你使用当前耐久度为 aa、防御等级为 bb 的盾牌与力量值为 dd 的怪物战斗时,会出现以下三种可能的结果:

  • 若 a=0a = 0,则你受到 dd 点伤害;
  • 若 a>0a \gt 0 且 d≥bd \ge b,则你不受到任何伤害,但盾牌的当前耐久度减少 11;
  • 若 a>0a \gt 0 且 d<bd \lt b,则什么也不会发生。

第 ii 只怪物的力量值为 did_i,你将恰好与每只怪物战斗一次,且战斗顺序是随机的(所有 n!n! 种排列等概率)。你共有 mm 面不同的盾牌可供选择,其中第 ii 面盾牌的初始耐久度为 aia_i、防御等级为 bib_i。对每面盾牌,请计算:若选用该盾牌,并以随机顺序与给定的 nn 只怪物战斗,你所受伤害的期望值。

输入格式

The first line contains two integers nn and mm (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5) — the number of monsters and the number of shields, respectively.

The second line contains nn integers d1d_1, d2d_2, ..., dnd_n (1≤di≤1091 \le d_i \le 10^9), where did_i is the strength of the ii-th monster.

Then mm lines follow, the ii-th of them contains two integers aia_i and bib_i (1≤ai≤n1 \le a_i \le n; 1≤bi≤1091 \le b_i \le 10^9) — the description of the ii-th shield.

第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5),分别表示怪物的数量和盾牌的数量。

第二行包含 nn 个整数 d1d_1, d2d_2, ..., dnd_n(1≤di≤1091 \le d_i \le 10^9),其中 did_i 表示第 ii 个怪物的强度。

接下来是 mm 行,其中第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai≤n1 \le a_i \le n;1≤bi≤1091 \le b_i \le 10^9),表示第 ii 个盾牌的描述。

输出格式

Print mm integers, where the ii-th integer represents the expected damage you receive with the ii-th shield as follows: it can be proven that, for each shield, the expected damage is an irreducible fraction xy\dfrac{x}{y}, where yy is coprime with 998244353998244353. You have to print the value of x⋅y−1 mod 998244353x \cdot y^{-1} \bmod 998244353, where y−1y^{-1} is the inverse element for yy (y⋅y−1 mod 998244353=1y \cdot y^{-1} \bmod 998244353 = 1).

输出 mm 个整数,其中第 ii 个整数表示使用第 ii 个护盾时你所受到的期望伤害。可以证明:对于每个护盾,其期望伤害均为一个既约分数 xy\dfrac{x}{y},其中 yy 与 998244353998244353 互质。你需要输出 x⋅y−1 mod 998244353x \cdot y^{-1} \bmod 998244353 的值,其中 y−1y^{-1} 是 yy 的模 998244353998244353 乘法逆元(即满足 y⋅y−1 mod 998244353=1y \cdot y^{-1} \bmod 998244353 = 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测评打分。不知道怎么写?

首页