아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Fancy Stack

시간 제한3초메모리 제한512 MB

요약
블록 크기의 순열 중에서 값이 오르내리기를 번갈아 하고 짝수 번째 위치의 값이 엄격히 증가하는 순열의 개수를 998244353으로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
조합론, 동적 계획법
정답자
아직 제출이 없습니다

문제

Little Fiona has a collection of nn blocks of various sizes a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n, where nn is even. Some of the blocks can be equal in size. She would like to put all these blocks one onto another to form a fancy stack.

Let b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n be the sizes of blocks in the stack from top to bottom. Since Fiona is using all her blocks, b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n must be a permutation of a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n. Fiona thinks the stack is fancy if both of the following conditions are satisfied:

  • The second block is strictly bigger than the first one, and then each block is alternately strictly smaller or strictly bigger than the previous one. Formally, b_1<b_2>b_3<b_4>…>b_n−1<b_nb\_1 < b\_2 > b\_3 < b\_4 > \ldots > b\_{n-1} < b\_n.
  • The sizes of the blocks on even positions are strictly increasing. Formally, b_2<b_4<b_6<…<b_nb\_2 < b\_4 < b\_6 < \ldots < b\_n (remember that nn is even).

Two stacks are considered different if their corresponding sequences b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n differ in at least one position.

Fiona wants to know how many different fancy stacks she can build with all of her blocks. Since large numbers scare Fiona, find this number modulo 998,244,353998\\,244\\,353.

입력

Each input contains multiple test cases. The first line contains the number of test cases tt (1≤t≤25001 \le t \le 2500). Description of the test cases follows.

The first line of each test case contains a single integer nn --- the number of blocks at Fiona's disposal (2≤n≤50002 \le n \le 5000; nn is even). The second line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n --- the sizes of the blocks in non-decreasing order (1≤a_1≤a_2≤⋯≤a_n≤n1 \le a\_1 \le a\_2 \le \dotsb \le a\_n \le n).

It is guaranteed that the sum of nn over all test cases does not exceed 50005000.

출력

For each test case, print the number of ways to build a fancy stack, modulo 998,244,353998\\,244\\,353.

예제1

  1. 예제 1

    입력
    2
    4
    1 2 3 4
    8
    1 1 2 3 4 4 6 7
    
    예상 출력
    2
    4