CF1809G.Prediction

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Consider a tournament with nn participants. The rating of the ii-th participant is aia_i.

The tournament will be organized as follows. First of all, organizers will assign each participant an index from 11 to nn. All indices will be unique. Let pip_i be the participant who gets the index ii.

Then, n−1n-1 games will be held. In the first game, participants p1p_1 and p2p_2 will play. In the second game, the winner of the first game will play against p3p_3. In the third game, the winner of the second game will play against p4p_4, and so on — in the last game, the winner of the (n−2)(n-2)-th game will play against pnp_n.

Monocarp wants to predict the results of all n−1n-1 games (of course, he will do the prediction only after the indices of the participants are assigned). He knows for sure that, when two participants with ratings xx and yy play, and ∣x−y∣>k|x - y| \gt k, the participant with the higher rating wins. But if ∣x−y∣≤k|x - y| \le k, any of the two participants may win.

Among all n!n! ways to assign the indices to participants, calculate the number of ways to do this so that Monocarp can predict the results of all n−1n-1 games. Since the answer can be large, print it modulo 998244353998244353.

考虑一场有 nn 名参赛者的锦标赛。第 ii 名参赛者的评分为 aia_i。

锦标赛将按如下方式组织:首先,主办方将为每名参赛者分配一个从 11 到 nn 的唯一索引。设 pip_i 表示获得索引 ii 的参赛者。

随后,将举行 n−1n-1 场比赛。第一场比赛由参赛者 p1p_1 和 p2p_2 进行;第二场比赛由第一场的胜者对阵 p3p_3;第三场比赛由第二场的胜者对阵 p4p_4;以此类推——最后一场(即第 n−1n-1 场)比赛由第 (n−2)(n-2) 场的胜者对阵 pnp_n。

Monocarp 希望预测全部 n−1n-1 场比赛的结果(当然,他仅在参赛者索引分配完成后才进行预测)。他确信:当两名评分为 xx 和 yy 的参赛者对战时,若 ∣x−y∣>k|x - y| > k,则评分更高者获胜;但若 ∣x−y∣≤k|x - y| \le k,则两人中任意一人皆可获胜。

在全部 n!n! 种为参赛者分配索引的方式中,计算使得 Monocarp 能够预测全部 n−1n-1 场比赛结果的分配方式数目。由于答案可能很大,请对 998244353998244353 取模后输出。

输入格式

The first line contains two integers nn and kk (2≤n≤1062 \le n \le 10^6; 0≤k≤1090 \le k \le 10^9).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤a1≤a2≤⋯≤an≤1090 \le a_1 \le a_2 \le \dots \le a_n \le 10^9).

第一行包含两个整数 nn 和 kk(2≤n≤1062 \le n \le 10^6;0≤k≤1090 \le k \le 10^9)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤a1≤a2≤⋯≤an≤1090 \le a_1 \le a_2 \le \dots \le a_n \le 10^9)。

输出格式

Print one integer — the number of ways to assign the indices to the participants so that Monocarp can predict the results of all n−1n-1 games.

输出一个整数——表示为参赛者分配编号的方式数量,使得 Monocarp 能够预测全部 n−1n-1 场比赛的结果。

输入输出样例

  • 输入#1

    4 3
    7 12 17 21

    输出#1

    24
  • 输入#2

    3 7
    4 9 28

    输出#2

    4
  • 输入#3

    4 1
    1 2 3 4

    输出#3

    0
  • 输入#4

    4 1
    1 2 2 4

    输出#4

    12
  • 输入#5

    16 30
    8 12 15 27 39 44 49 50 51 53 58 58 59 67 68 100

    输出#5

    527461297

说明/提示

In the first example, a match with any pair of players can be predicted by Monocarp, so all 2424 ways to assign indices should be counted.

In the second example, suitable ways are [1,3,2][1, 3, 2], [2,3,1][2, 3, 1], [3,1,2[3, 1, 2] and [3,2,1][3, 2, 1].

在第一个例子中,Monocarp 可以预测任意一对选手之间的比赛,因此所有 2424 种编号分配方式均应被计入。

在第二个例子中,符合条件的编号分配方式为 [1,3,2][1, 3, 2]、[2,3,1][2, 3, 1]、[3,1,2][3, 1, 2] 和 [3,2,1][3, 2, 1]。

输入解题思路,AI测评打分。不知道怎么写?

首页