P15745 [CodeChef] EQSS
提高+
题目描述

Chef has a sequence A of $2 \cdot N$ integers containing all natural numbers from 1 to N exactly twice.

Let a sequence B containing K elements be a [subsequence] of A. We define $a strictly increasing *index* sequence I(B) = [I_{1}, I_{2}, \ldots, I_{K}]$ such that, B can be written as $[A_{I_{1}}, A_{I_{2}}, \ldots, A_{I_{K}}]$.

A pair of subsequences (P,Q) is said to be good if all of the following conditions satisfy:
Both subsequences have the same length. In other words, |P| = |Q|, where |P| and |Q| denote the lengths of P and Q respectively;
The subsequences P and Q are disjoint. In other words, there are no common elements between I(P) and I(Q);
The subsequences are equal. In other words, P_{j} = Q_{j} for all (1≤ j ≤ |P|).

Find the total number of distinct ordered pairs of subsequences (P,Q) that are good.
Two ordered pairs (P_{1}, Q_{1}) and (P_{2}, Q_{2}) are considered different iff $I(P_{1}) \ne I(P_{2})$ or $I(Q_{1}) \ne I(Q_{2})$.

Since the answer can be very large, print it modulo 998244353.

------ Input Format ------

  • First line contains T − the number of test cases. The description of the test cases is as follows.
  • The first line of each test case contains a single integer N − the value of N.
  • The second line of each test case contains $2 \cdot N integers A_{1}, A_{2}, \ldots, A_{2 \cdot N}$​.

------ Output Format ------

For each test case, output a single integer − the total number of distinct ordered pairs of subsequences (P,Q) that are good modulo 998244353.

------ Constraints ------

$1 ≤ T ≤ 2\cdot 10^{5}$
$1 ≤ N ≤ 2\cdot 10^{5}$
$1 ≤ A_{i} ≤ N$
- Sum of $N$ over all test cases does not exceed $6\cdot 10^{5}$.

----- Sample Input 1 ------
3
1
1 1
2
1 1 2 2
2
1 2 1 2
----- Sample Output 1 ------
2
8
6
----- explanation 1 ------
Test case $1$: Possible ordered pairs are: $([A_{1}], [A_{2}])$, $([A_{2}], [A_{1}])$.

Test case $2$: Possible ordered pairs are: $([A_{1}],[A_{2}])$, $([A_{2}], [A_{1}])$, $([A_{3}], [A_{4}])$, $([A_{4}], [A_{3}])$, $([A_{1}, A_{3}], [A_{2}, A_{4}])$, $([A_{2}, A_{4}], [A_{1}, A_{3}])$, $([A_{1}, A_{4}], [A_{2}, A_{3}])$, $([A_{2}, A_{3}], [A_{1}, A_{4}])$.

输入格式

见题面

输出格式

见题面

样例输入
3 1 1 1 2 1 1 2 2 2 1 2 1 2
样例输出
2 8 6