You are given a permutation of integers from 1 to 2 𝑁 2N, but some elements are missing…
- User
You are given a permutation of integers from 1 to 2 𝑁 2N, but some elements are missing and are represented as zeros. The missing elements are located at even positions in the permutation, while the odd positions may or may not have zeros. Your task is to determine the number of ways to fill the zeros in such a way that the following sum is maximized:
∣ 𝑃 1 − 𝑃 2 ∣ + ∣ 𝑃 3 − 𝑃 4 ∣ + ⋯ + ∣ 𝑃 2 𝑁 − 1 − 𝑃 2 𝑁 ∣ ∣P 1 −P 2 ∣+∣P 3 −P 4 ∣+⋯+∣P 2N−1 −P 2N ∣ The solution should be computed modulo 998244353 998244353.
Constraints: 𝑇 T: Number of test cases ( 1 ≤ 𝑇 ≤ 1 0 5 1≤T≤10 5 ) Each test case consists of: 𝑁 N: Integer, where the length of the permutation 𝑃 P is 2 𝑁 2N ( 1 ≤ 𝑁 ≤ 2 × 1 0 5 1≤N≤2×10 5 ) 𝑃 P: An array of length 2 𝑁 2N where elements at even positions are always zeros, and elements at odd positions may be non-zero or zero. The sum of 𝑁 N across all test cases does not exceed 2 × 1 0 5 2×10 5 . All non-zero elements in 𝑃 P are distinct. Key Constraints: Even positions are always zero: 𝑃 2 , 𝑃 4 , 𝑃 6 , … , 𝑃 2 𝑁
0 P 2 ,P 4 ,P 6 ,…,P 2N =0. Odd positions can be zero or filled with distinct integers. Maximizing the sum of absolute differences: The task requires you to maximize the sum of absolute differences between consecutive pairs of elements. Goal: For each test case, find how many ways you can fill the zeros to get a valid permutation that maximizes the required sum, and output the result modulo 998244353 998244353.
This is the easy version of the problem. Here, it is guaranteed that P 2 i
0 P 2i =0 for all i i.
You are given a permutation † †
P P of the integers 1 1 to 2 N 2N, with some of its elements missing (represented by 0 0's). Find the number of ways of filling in the zeros to obtain a valid permutation, such that the quantity
∣ P 1 − P 2 ∣ + ∣ P 3 − P 4 ∣ + … + ∣ P 2 N − 1 − P 2 N ∣ ∣P 1 −P 2 ∣+∣P 3 −P 4 ∣+…+∣P 2N−1 −P 2N ∣ is maximized.
In this version of the problem, there is an additional constraint on the input: all the elements at even positions are 0 0, that is, P 2
P 4
P 6
…
P 2 N
0 P 2 =P 4 =P 6 =…=P 2N =0. Note that the elements at odd positions may or may not be zero.
The answer can be large, so find it modulo 998244353 998244353.
† † A permutation of the integers 1 1 to N N is an array of length N N that contains every integer from 1 1 to N N exactly once.
Input Format The first line of input will contain a single integer T T, denoting the number of test cases. Each test case consists of two lines of input. The first line of each test case contains a single integer N N — meaning that P P has length 2 N 2N. The second line contains 2 N 2N space-separated integers P 1 , P 2 , … , P 2 N P 1 ,P 2 ,…,P 2N . Output Format For each test case, output on a new line the number of ways of filling in the zeros to maximize the sum, modulo 998244353 998244353.
- Assistant