CF1770D.Koxia and Game

普及/提高-

通过率:0%

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).

输入格式

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 .

输出格式

Output a single integer — the number of cc makes Koxia win, modulo 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.

首页