CF1418E.Expected Damage

普及/提高-

通过率:0%

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 > 0 and dbd \ge b , you receive no damage, but the current durability of the shield decreases by 11 ;
  • if a>0a > 0 and d<bd < 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.

输入格式

The first line contains two integers nn and mm ( 1n,m21051 \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 ( 1di1091 \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 ( 1ain1 \le a_i \le n ; 1bi1091 \le b_i \le 10^9 ) — the description of the ii -th shield.

输出格式

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 xy1mod998244353x \cdot y^{-1} \bmod 998244353 , where y1y^{-1} is the inverse element for yy ( yy1mod998244353=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
首页