CF1666F.Fancy Stack
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Fiona has a collection of n blocks of various sizes a1,a2,…,an, where n 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 b1,b2,…,bn be the sizes of blocks in the stack from top to bottom. Since Fiona is using all her blocks, b1,b2,…,bn must be a permutation of a1,a2,…,an. 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, b1<b2>b3<b4>…>bn−1<bn.
- The sizes of the blocks on even positions are strictly increasing. Formally, b2<b4<b6<…<bn (remember that n is even).

Two stacks are considered different if their corresponding sequences b1,b2,…,bn 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 998244353.
小菲奥娜有一组 n 个大小各异的积木,大小分别为 a1,a2,…,an,其中 n 为偶数。部分积木的大小可能相等。她希望将所有这些积木自上而下叠放成一个“花式”堆叠。
设堆叠中自上而下的积木大小依次为 b1,b2,…,bn。由于菲奥娜使用了全部积木,因此 b1,b2,…,bn 必须是 a1,a2,…,an 的一个排列。菲奥娜认为该堆叠是“花式”的,当且仅当同时满足以下两个条件:
- 第二块积木严格大于第一块,之后每一块积木与前一块严格交替地更小或更大。形式化地,满足:
b1<b2>b3<b4>…>bn−1<bn。 - 所有位于偶数位置(即第 2,4,6,…,n 位)的积木大小严格递增。形式化地,满足:
b2<b4<b6<…<bn(注意 n 是偶数)。

若两个堆叠对应的序列 b1,b2,…,bn 至少在一个位置上不同,则认为它们是不同的堆叠。
菲奥娜想知道:用她所有的积木,一共能搭建出多少种不同的“花式”堆叠?由于大数会吓到菲奥娜,请将该数目对 998244353 取模后输出。
输入格式
Each input contains multiple test cases. The first line contains the number of test cases t (1≤t≤2500). Description of the test cases follows.
The first line of each test case contains a single integer n — the number of blocks at Fiona's disposal (2≤n≤5000; n is even). The second line contains n integers a1,a2,…,an — the sizes of the blocks in non-decreasing order (1≤a1≤a2≤⋯≤an≤n).
It is guaranteed that the sum of n over all test cases does not exceed 5000.
每个输入包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤2500)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n —— Fiona 所拥有的方块数量(2≤n≤5000;且 n 为偶数)。第二行包含 n 个整数 a1,a2,…,an —— 方块的尺寸,按非递减顺序排列(1≤a1≤a2≤⋯≤an≤n)。
保证所有测试用例中 n 的总和不超过 5000。
输出格式
For each test case, print the number of ways to build a fancy stack, modulo 998244353.
对于每个测试用例,输出构建一个“花式”堆栈的方案数,对 998244353 取模。
输入输出样例
输入#1
2 4 1 2 3 4 8 1 1 2 3 4 4 6 7
输出#1
2 4
输入解题思路,AI测评打分。不知道怎么写?