311298: CF1967E1. Again Counting Arrays (Easy Version)

Memory Limit:512 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E1. Again Counting Arrays (Easy Version)time limit per test5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard output

This is the easy version of the problem. The differences between the two versions are the constraints on $n, m, b_0$ and the time limit. You can make hacks only if both versions are solved.

Little R has counted many sets before, and now she decides to count arrays.

Little R thinks an array $b_0, \ldots, b_n$ consisting of non-negative integers is continuous if and only if, for each $i$ such that $1 \leq i \leq n$, $\lvert b_i - b_{i-1} \rvert = 1$ is satisfied. She likes continuity, so she only wants to generate continuous arrays.

If Little R is given $b_0$ and $a_1, \ldots, a_n$, she will try to generate a non-negative continuous array $b$, which has no similarity with $a$. More formally, for all $1 \leq i \leq n$, $a_i \neq b_i$ holds.

However, Little R does not have any array $a$. Instead, she gives you $n$, $m$ and $b_0$. She wants to count the different integer arrays $a_1, \ldots, a_n$ satisfying:

  • $1 \leq a_i \leq m$;
  • At least one non-negative continuous array $b_0, \ldots, b_n$ can be generated.

Note that $b_i \geq 0$, but the $b_i$ can be arbitrarily large.

Since the actual answer may be enormous, please just tell her the answer modulo $998\,244\,353$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t\ (1 \leq t \leq 10^4)$. The description of the test cases follows.

The first and only line of each test case contains three integers $n$, $m$, and $b_0$ ($1 \leq n \leq 2 \cdot 10^5$, $1 \leq m \leq 2 \cdot 10^5$, $0 \leq b_0 \leq 2\cdot 10^5$) — the length of the array $a_1, \ldots, a_n$, the maximum possible element in $a_1, \ldots, a_n$, and the initial element of the array $b_0, \ldots, b_n$.

It is guaranteed that the sum of $n$ over all test cases does not exceeds $2\cdot 10^5$.

Output

For each test case, output a single line containing an integer: the number of different arrays $a_1, \ldots, a_n$ satisfying the conditions, modulo $998\,244\,353$.

ExampleInput
6
3 2 1
5 5 3
13 4 1
100 6 7
100 11 3
1000 424 132
Output
6
3120
59982228
943484039
644081522
501350342
Note

In the first test case, for example, when $a = [1, 2, 1]$, we can set $b = [1, 0, 1, 0]$. When $a = [1, 1, 2]$, we can set $b = [1, 2, 3, 4]$. In total, there are $6$ valid choices of $a_1, \ldots, a_n$: in fact, it can be proved that only $a = [2, 1, 1]$ and $a = [2, 1, 2]$ make it impossible to construct a non-negative continuous $b_0, \ldots, b_n$, so the answer is $2^3 - 2 = 6$.

Output

题目大意:
这是一个关于生成特定类型数组的计数问题。给定一个非负整数数组b0, ..., bn,如果对于每个1 ≤ i ≤ n,都满足|bi - bi-1| = 1,则称这个数组是连续的。现在,给定一个整数b0和另一个整数数组a1, ..., an,要生成一个非负的连续数组b,且b与a不相似,即对于所有1 ≤ i ≤ n,有ai ≠ bi。现在没有给出数组a,而是给出n, m和b0,要求计算有多少种不同的整数数组a1, ..., an满足以下条件:
1. 1 ≤ ai ≤ m;
2. 可以生成至少一个非负连续数组b0, ..., bn。

输入输出数据格式:
输入:
- 第一行包含一个整数t(1 ≤ t ≤ 10^4),表示测试用例的数量。
- 每个测试用例包含一行,包含三个整数n, m, 和b0(1 ≤ n ≤ 2 × 10^5,1 ≤ m ≤ 2 × 10^5,0 ≤ b0 ≤ 2 × 10^5)——数组a1, ..., an的长度,a1, ..., an中最大可能的元素,以及数组b0, ..., bn的初始元素。

输出:
- 对于每个测试用例,输出一行,包含一个整数:满足条件的不同数组a1, ..., an的数量,模998,244,353。

注意:由于实际答案可能非常大,只需给出模998,244,353的结果。题目大意: 这是一个关于生成特定类型数组的计数问题。给定一个非负整数数组b0, ..., bn,如果对于每个1 ≤ i ≤ n,都满足|bi - bi-1| = 1,则称这个数组是连续的。现在,给定一个整数b0和另一个整数数组a1, ..., an,要生成一个非负的连续数组b,且b与a不相似,即对于所有1 ≤ i ≤ n,有ai ≠ bi。现在没有给出数组a,而是给出n, m和b0,要求计算有多少种不同的整数数组a1, ..., an满足以下条件: 1. 1 ≤ ai ≤ m; 2. 可以生成至少一个非负连续数组b0, ..., bn。 输入输出数据格式: 输入: - 第一行包含一个整数t(1 ≤ t ≤ 10^4),表示测试用例的数量。 - 每个测试用例包含一行,包含三个整数n, m, 和b0(1 ≤ n ≤ 2 × 10^5,1 ≤ m ≤ 2 × 10^5,0 ≤ b0 ≤ 2 × 10^5)——数组a1, ..., an的长度,a1, ..., an中最大可能的元素,以及数组b0, ..., bn的初始元素。 输出: - 对于每个测试用例,输出一行,包含一个整数:满足条件的不同数组a1, ..., an的数量,模998,244,353。 注意:由于实际答案可能非常大,只需给出模998,244,353的结果。

加入题单

上一题 下一题 算法标签: