AT_abc463_g.Random Walk Distance

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given a positive integer NN and an integer XX.

Takahashi is at coordinate 00 on a number line. He will now perform the following move NN times:

  • When at coordinate xx, choose coordinate x−1x-1 or coordinate x+1x+1 with equal probability and move there.

The choices of destination across the NN moves are all independent. Let x′x' be the coordinate after all NN moves. Find the expected value, modulo 998244353998244353, of ∣x′−X∣|x'-X|.

You are given TT test cases; solve each of them.

Definition of expected value modulo 998244353998244353

It can be proved that the sought expected value is always a rational number. Moreover, under the constraints of this problem, it can be proved that when expressed as an irreducible fraction PQ\frac{P}{Q}, we have Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}. Therefore, there is a unique integer RR satisfying R×Q≡P(mod998244353),0≤R<998244353R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353. Find this RR.

给定一个正整数 NN 和一个整数 XX。

高桥位于数轴上的坐标 00 处。他将执行以下操作共 NN 次:

  • 当前位于坐标 xx 时,以相等的概率选择坐标 x−1x-1 或 x+1x+1,并移动到该位置。

这 NN 次移动中每次的选择相互独立。设 NN 次移动后最终坐标为 x′x'。求 ∣x′−X∣|x'-X| 的期望值对 998244353998244353 取模的结果。

你将得到 TT 组测试用例,请分别求解每组。

期望值对 998244353998244353 取模的定义

可以证明:所求期望值恒为有理数。此外,在本题约束下,可进一步证明:若将该期望值表示为既约分数 PQ\frac{P}{Q},则必有 Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}。因此,存在唯一整数 RR 满足 R×Q≡P(mod998244353)R \times Q \equiv P \pmod{998244353} 且 0≤R<9982443530 \leq R < 998244353。请输出该 RR。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each casei\mathrm{case}_i is the ii-th test case and is given in the following format:

NN XX

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个 casei\mathrm{case}_i 表示第 ii 个测试用例,其格式如下:

NN XX

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

输入输出样例

  • 输入#1

    5
    3 2
    6 4
    2026 -620
    12345 67890
    98765 -43210

    输出#1

    748683267
    935854085
    270602660
    67890
    844852181

说明/提示

Sample 1 Explanation:
For the first test case, Takahashi ends up at coordinate −3-3 with probability 18\frac{1}{8}, at coordinate −1-1 with probability 38\frac{3}{8}, at coordinate 11 with probability 38\frac{3}{8}, and at coordinate 33 with probability 18\frac{1}{8}. Thus, the expected value of ∣x′−X∣|x'-X| is 18⋅∣−3−2∣+38⋅∣−1−2∣+38⋅∣1−2∣+18⋅∣3−2∣=94\frac{1}{8}\cdot|{-3}-2|+\frac{3}{8}\cdot|{-1}-2|+\frac{3}{8}\cdot|1-2|+\frac{1}{8}\cdot|3-2|=\frac{9}{4}.

Constraints

  • 1≤T≤2×1051 \leq T \leq 2 \times 10^5
  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5
  • ∣X∣≤2×105|X| \leq 2 \times 10^5
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,高桥最终位于坐标 −3-3 的概率为 18\frac{1}{8},位于坐标 −1-1 的概率为 38\frac{3}{8},位于坐标 11 的概率为 38\frac{3}{8},位于坐标 33 的概率为 18\frac{1}{8}。因此,∣x′−X∣|x'-X| 的期望值为

18⋅∣−3−2∣+38⋅∣−1−2∣+38⋅∣1−2∣+18⋅∣3−2∣=94.\frac{1}{8}\cdot|{-3}-2|+\frac{3}{8}\cdot|{-1}-2|+\frac{3}{8}\cdot|1-2|+\frac{1}{8}\cdot|3-2|=\frac{9}{4}.

限制条件

  • 1≤T≤2×1051 \leq T \leq 2 \times 10^5
  • 1≤N≤2×1051 \leq N \leq 2 \times 10^5
  • ∣X∣≤2×105|X| \leq 2 \times 10^5
  • 所有输入值均为整数。

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

首页