AT_arc223_b.Valid Arrays by K-Divisible Swaps

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given an integer sequence AA of length NN and a positive integer KK.
You can perform the following operation on AA any number of times:

  • Choose an integer ii with 1≤i≤N−11 \leq i \leq N-1 such that Ai+Ai+1A_i + A_{i+1} is divisible by KK, and swap AiA_i and Ai+1A_{i+1}.

Find the total number, modulo 998244353998244353, of distinct sequences that AA can become after performing the operation zero or more times.

Solve TT test cases per input.

给你一个长度为 NN 的整数序列 AA 和一个正整数 KK。
你可以对 AA 执行以下操作任意多次:

  • 选择一个满足 1≤i≤N−11 \leq i \leq N-1 的整数 ii,使得 Ai+Ai+1A_i + A_{i+1} 能被 KK 整除,然后交换 AiA_i 和 Ai+1A_{i+1}。

求在执行零次或多次上述操作后,AA 可能变成的不同序列的总数(对 998244353998244353 取模)。

每组输入包含 TT 个测试用例。

输入格式

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 test case caset\mathrm{case}_t is given in the following format:

NN KK
A1A_1 A2A_2 …\dots ANA_N

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

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

每个测试用例 caset\mathrm{case}_t 的格式如下:

NN KK
A1A_1 A2A_2 …\dots ANA_N

输出格式

Output the answers over a total of TT lines. The tt-th line should contain the answer for the tt-th test case.

在总共 TT 行中输出答案。第 tt 行应包含第 tt 个测试用例的答案。

输入输出样例

  • 输入#1

    3
    4 3
    1 2 4 7
    6 4
    1 5 3 6 2 4
    3 2
    2 2 3

    输出#1

    4
    6
    1

说明/提示

Sample 1 Explanation:
For the first test case, the sequences that AA can become after performing the operation zero or more times are these four: (1,2,4,7),(1,4,2,7),(1,4,7,2),(2,1,4,7)(1,2,4,7),(1,4,2,7),(1,4,7,2),(2,1,4,7).

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤2×1052 \leq N \leq 2 \times 10^5
  • 1≤K≤1091 \leq K \leq 10^9
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • The sum of NN over all test cases is at most 2×1052 \times 10^5.
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,序列 AA 在执行零次或多次操作后可能变成以下四种序列:(1,2,4,7)(1,2,4,7)、(1,4,2,7)(1,4,2,7)、(1,4,7,2)(1,4,7,2)、(2,1,4,7)(2,1,4,7)。

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤2×1052 \leq N \leq 2 \times 10^5
  • 1≤K≤1091 \leq K \leq 10^9
  • 1≤Ai≤1091 \leq A_i \leq 10^9
  • 所有测试用例的 NN 之和不超过 2×1052 \times 10^5。
  • 所有输入值均为整数。

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

首页