AT_arc223_b.Valid Arrays by K-Divisible Swaps
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer sequence A of length N and a positive integer K.
You can perform the following operation on A any number of times:
- Choose an integer i with 1≤i≤N−1 such that Ai+Ai+1 is divisible by K, and swap Ai and Ai+1.
Find the total number, modulo 998244353, of distinct sequences that A can become after performing the operation zero or more times.
Solve T test cases per input.
给你一个长度为 N 的整数序列 A 和一个正整数 K。
你可以对 A 执行以下操作任意多次:
- 选择一个满足 1≤i≤N−1 的整数 i,使得 Ai+Ai+1 能被 K 整除,然后交换 Ai 和 Ai+1。
求在执行零次或多次上述操作后,A 可能变成的不同序列的总数(对 998244353 取模)。
每组输入包含 T 个测试用例。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case caset is given in the following format:
N K
A1 A2 … AN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例 caset 的格式如下:
N K
A1 A2 … AN
输出格式
Output the answers over a total of T lines. The t-th line should contain the answer for the t-th test case.
在总共 T 行中输出答案。第 t 行应包含第 t 个测试用例的答案。
输入输出样例
输入#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 A 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).
Constraints
- 1≤T≤105
- 2≤N≤2×105
- 1≤K≤109
- 1≤Ai≤109
- The sum of N over all test cases is at most 2×105.
- All input values are integers.
样例 1 解释:
对于第一个测试用例,序列 A 在执行零次或多次操作后可能变成以下四种序列:(1,2,4,7)、(1,4,2,7)、(1,4,7,2)、(2,1,4,7)。
约束条件
- 1≤T≤105
- 2≤N≤2×105
- 1≤K≤109
- 1≤Ai≤109
- 所有测试用例的 N 之和不超过 2×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?