CF1770D.Koxia and Game

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Koxia and Mahiru are playing a game with three arrays aa, bb, and cc of length nn. Each element of aa, bb and cc is an integer between 11 and nn inclusive.

The game consists of nn rounds. In the ii-th round, they perform the following moves:

  • Let SS be the multiset ai,bi,ci{a_i, b_i, c_i}.
  • Koxia removes one element from the multiset SS by her choice.
  • Mahiru chooses one integer from the two remaining in the multiset SS.

Let did_i be the integer Mahiru chose in the ii-th round. If dd is a permutation^\dagger, Koxia wins. Otherwise, Mahiru wins.

Currently, only the arrays aa and bb have been chosen. As an avid supporter of Koxia, you want to choose an array cc such that Koxia will win. Count the number of such cc, modulo 998244353998\,244\,353.

Note that Koxia and Mahiru both play optimally.

^\dagger A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

Koxia 和 Mahiru 正在玩一个涉及三个长度为 nn 的数组 aabbcc 的游戏。数组 aabbcc 的每个元素均为介于 11nn(含)之间的整数。

游戏共进行 nn 轮。在第 ii 轮中,他们执行以下操作:

  • SS 为多重集 {ai,bi,ci}\{a_i, b_i, c_i\}
  • Koxia 自主选择并从多重集 SS 中移除一个元素。
  • Mahiru 从 SS 中剩余的两个元素中任选一个整数。

did_i 表示 Mahiru 在第 ii 轮中所选的整数。若数组 d=[d1,d2,,dn]d = [d_1, d_2, \dots, d_n] 是一个排列^\dagger,则 Koxia 获胜;否则 Mahiru 获胜。

目前,仅数组 aabb 已被选定。作为 Koxia 的忠实支持者,你希望选定一个数组 cc,使得 Koxia 必然获胜。请计算满足条件的数组 cc 的个数,并对 998244353998\,244\,353 取模。

注意:Koxia 和 Mahiru 均采取最优策略。

^\dagger 长度为 nn排列指由 11nn(含)这 nn 个互不相同的整数以任意顺序组成的数组。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n = 3,但数组中出现了 44)。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1t21041 \leq t \leq 2 \cdot 10^4) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n1051 \leq n \leq {10}^5) — the size of the arrays.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ain1 \leq a_i \leq n).

The third line of each test case contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n (1bin1 \leq b_i \leq n).

It is guaranteed that the sum of nn over all test cases does not exceed 105{10}^5.

每个测试包含多个测试用例。第一行包含一个整数 tt1t21041 \leq t \leq 2 \cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn1n1051 \leq n \leq {10}^5),表示数组的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,,ana_1, a_2, \dots, a_n1ain1 \leq a_i \leq n)。

每个测试用例的第三行包含 nn 个整数 b1,b2,,bnb_1, b_2, \dots, b_n1bin1 \leq b_i \leq n)。

保证所有测试用例的 nn 值之和不超过 105{10}^5

输出格式

Output a single integer — the number of cc makes Koxia win, modulo 998244353998\,244\,353.

输出一个整数——使得 Koxia 获胜的 cc 的个数,对 998244353998\,244\,353 取模。

输入输出样例

  • 输入#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 66 possible arrays cc that make Koxia win — [1,2,3][1, 2, 3], [1,3,2][1, 3, 2], [2,2,3][2, 2, 3], [2,3,2][2, 3, 2], [3,2,3][3, 2, 3], [3,3,2][3, 3, 2].

In the second test case, it can be proved that no array cc makes Koxia win.

在第一个测试用例中,共有 66 种可能的数组 cc 可使 Koxia 获胜——[1,2,3][1, 2, 3][1,3,2][1, 3, 2][2,2,3][2, 2, 3][2,3,2][2, 3, 2][3,2,3][3, 2, 3][3,3,2][3, 3, 2]

在第二个测试用例中,可以证明不存在任何数组 cc 能使 Koxia 获胜。

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

首页