CF1770D.Koxia and Game
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Koxia and Mahiru are playing a game with three arrays a, b, and c of length n. Each element of a, b and c is an integer between 1 and n inclusive.
The game consists of n rounds. In the i-th round, they perform the following moves:
- Let S be the multiset ai,bi,ci.
- Koxia removes one element from the multiset S by her choice.
- Mahiru chooses one integer from the two remaining in the multiset S.
Let di be the integer Mahiru chose in the i-th round. If d is a permutation†, Koxia wins. Otherwise, Mahiru wins.
Currently, only the arrays a and b have been chosen. As an avid supporter of Koxia, you want to choose an array c such that Koxia will win. Count the number of such c, modulo 998244353.
Note that Koxia and Mahiru both play optimally.
† A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array), and [1,3,4] is also not a permutation (n=3 but there is 4 in the array).
Koxia 和 Mahiru 正在玩一个涉及三个长度为 n 的数组 a、b 和 c 的游戏。数组 a、b 和 c 的每个元素均为介于 1 到 n(含)之间的整数。
游戏共进行 n 轮。在第 i 轮中,他们执行以下操作:
- 令 S 为多重集 {ai,bi,ci}。
- Koxia 自主选择并从多重集 S 中移除一个元素。
- Mahiru 从 S 中剩余的两个元素中任选一个整数。
设 di 表示 Mahiru 在第 i 轮中所选的整数。若数组 d=[d1,d2,…,dn] 是一个排列†,则 Koxia 获胜;否则 Mahiru 获胜。
目前,仅数组 a 和 b 已被选定。作为 Koxia 的忠实支持者,你希望选定一个数组 c,使得 Koxia 必然获胜。请计算满足条件的数组 c 的个数,并对 998244353 取模。
注意:Koxia 和 Mahiru 均采取最优策略。
† 长度为 n 的排列指由 1 到 n(含)这 n 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4] 是一个排列,但 [1,2,2] 不是排列(数组中 2 出现了两次),[1,3,4] 也不是排列(此时 n=3,但数组中出现了 4)。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤2⋅104) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (1≤n≤105) — the size of the arrays.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n).
The third line of each test case contains n integers b1,b2,…,bn (1≤bi≤n).
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤2⋅104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105),表示数组的大小。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤n)。
保证所有测试用例的 n 值之和不超过 105。
输出格式
Output a single integer — the number of c makes Koxia win, modulo 998244353.
输出一个整数——使得 Koxia 获胜的 c 的个数,对 998244353 取模。
输入输出样例
输入#1
2 3 1 2 2 1 3 3 5 3 3 1 3 4 4 5 2 5 5
输出#1
6 0
说明/提示
In the first test case, there are 6 possible arrays c that make Koxia win — [1,2,3], [1,3,2], [2,2,3], [2,3,2], [3,2,3], [3,3,2].
In the second test case, it can be proved that no array c makes Koxia win.
在第一个测试用例中,共有 6 种可能的数组 c 可使 Koxia 获胜——[1,2,3]、[1,3,2]、[2,2,3]、[2,3,2]、[3,2,3]、[3,3,2]。
在第二个测试用例中,可以证明不存在任何数组 c 能使 Koxia 获胜。
输入解题思路,AI测评打分。不知道怎么写?