CF2205E.Simons and Dividing the Rhythm

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

I grip my troubles within my hand, then hurl them off a thousand lands.

— SHUN, ONMYWAY

Consider that Simons is given an array aa of size mm.

Simons must operate on the array exactly once as follows:

  • First, he has to select an integer kk and choose kk pairs of integers [l1,r1],[l2,r2],…,[lk,rk][l_1,r_1],[l_2,r_2],\ldots,[l_k,r_k], such that:
    • li≤ril_i\le r_i for each 1≤i≤k1\le i\le k,
    • l1=1l_1=1, rk=mr_k=m, and
    • ri+1=li+1r_i+1=l_{i+1} for each ii from 11 to k−1k-1.
  • Then, he reverses each subarray [ali,ali+1,…,ari][a_{l_i},a_{l_i+1},\ldots, a_{r_i}] independently. After this, the array will become [ar1,ar1−1,…,al1,ar2,…,alk−1,ark,ark−1,…,alk][a_{r_1},a_{r_1-1},\ldots,a_{l_1},a_{r_2},\ldots,a_{l_{k-1}},a_{r_{k}},a_{r_k-1},\ldots,a_{l_k}].

You are given an array TT of size nn. Count the number of arrays SS such that Simons can transform SS to TT, modulo 998 244 353998\,244\,353.

我将烦恼紧握于掌中,然后将其掷向千里之外。

—— SHUN,《ONMYWAY》Spotify 链接

考虑 Simons 被给定一个长度为 mm 的数组 aa。

Simons 必须对这个数组恰好执行一次如下操作:

  • 首先,他需选定一个整数 kk,并选择 kk 对整数 [l1,r1],[l2,r2],…,[lk,rk][l_1,r_1],[l_2,r_2],\ldots,[l_k,r_k],满足:
    • 对每个 1≤i≤k1\le i\le k,有 li≤ril_i\le r_i;
    • l1=1l_1=1,rk=mr_k=m;
    • 对每个 i=1i = 1 到 k−1k-1,有 ri+1=li+1r_i+1=l_{i+1}。
  • 然后,他独立地将每个子数组 [ali,ali+1,…,ari][a_{l_i},a_{l_i+1},\ldots, a_{r_i}] 进行翻转。操作完成后,数组变为
    [ar1,ar1−1,…,al1,ar2,…,alk−1,ark,ark−1,…,alk][a_{r_1},a_{r_1-1},\ldots,a_{l_1},a_{r_2},\ldots,a_{l_{k-1}},a_{r_{k}},a_{r_k-1},\ldots,a_{l_k}]。

现给定一个长度为 nn 的数组 TT。请计算满足“Simons 可将数组 SS 经上述操作变换为 TT”的数组 SS 的个数,结果对 998 244 353998\,244\,353 取模。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤80001 \le t \le 8000). The description of the test cases follows.

The first line contains an integer nn (1≤n≤80001\le n\le 8000) — the length of TT.

The second line contains nn integers T1,T2,…,TnT_1,T_2,\ldots,T_n (1≤Ti≤80001\le T_i\le 8000) — the elements of TT.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤80001 \le t \le 8000)。随后是各测试用例的描述。

第一行包含一个整数 nn(1≤n≤80001\le n\le 8000)——即序列 TT 的长度。

第二行包含 nn 个整数 T1,T2,…,TnT_1,T_2,\ldots,T_n(1≤Ti≤80001\le T_i\le 8000)——即 TT 的各个元素。

保证所有测试用例的 nn 值之和不超过 80008000。

输出格式

For each test case, output a single integer — the number of arrays SS, modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——满足条件的数组 SS 的个数,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    5
    4
    1 1 2 1
    4
    1 2 3 1
    6
    1 3 2 3 3 2
    10
    2 3 1 4 3 1 4 3 1 2
    1
    8000

    输出#1

    4
    7
    22
    383
    1

说明/提示

In the first test case, we can see only the following arrays can be transformed to TT:

  • For S=[2,1,1,1]S=[2,1,1,1], Simons will choose [1,3][1,3] and [4,4][4,4]. Thus, the array will become [1,1,2,1][1,1,2,1], equal to TT.
  • For S=[1,2,1,1]S=[1,2,1,1], Simons will choose [1,4][1,4].
  • For S=[1,1,2,1]S=[1,1,2,1], Simons will choose [1,2][1,2], [3,3][3,3], and [4,4][4,4].
  • For S=[1,1,1,2]S=[1,1,1,2], Simons will choose [1,2][1,2] and [3,4][3,4].

In the second test case, we can see only the following arrays can be transformed to TT:

  • For S=[1,1,3,2]S=[1,1,3,2], Simons will choose [1,1][1,1] and [2,4][2,4].
  • For S=[1,2,1,3]S=[1,2,1,3], Simons will choose [1,1][1,1], [2,2][2,2], and [3,4][3,4].
  • For S=[1,2,3,1]S=[1,2,3,1], Simons will choose [1,1][1,1], [2,2][2,2], [3,3][3,3], and [4,4][4,4].
  • For S=[1,3,2,1]S=[1,3,2,1], Simons will choose [1,4][1,4].
  • For S=[2,1,1,3]S=[2,1,1,3], Simons will choose [1,2][1,2] and [3,4][3,4].
  • For S=[2,1,3,1]S=[2,1,3,1], Simons will choose [1,2][1,2], [3,3][3,3], and [4,4][4,4].
  • For S=[3,2,1,1]S=[3,2,1,1], Simons will choose [1,3][1,3] and [4,4][4,4].

在第一个测试用例中,我们只能看到以下数组可以被变换为 TT:

  • 对于 S=[2,1,1,1]S=[2,1,1,1],Simon 将选择区间 [1,3][1,3] 和 [4,4][4,4]。于是,该数组将变为 [1,1,2,1][1,1,2,1],与 TT 相等。
  • 对于 S=[1,2,1,1]S=[1,2,1,1],Simon 将选择区间 [1,4][1,4]。
  • 对于 S=[1,1,2,1]S=[1,1,2,1],Simon 将选择区间 [1,2][1,2]、[3,3][3,3] 和 [4,4][4,4]。
  • 对于 S=[1,1,1,2]S=[1,1,1,2],Simon 将选择区间 [1,2][1,2] 和 [3,4][3,4]。

在第二个测试用例中,我们只能看到以下数组可以被变换为 TT:

  • 对于 S=[1,1,3,2]S=[1,1,3,2],Simon 将选择区间 [1,1][1,1] 和 [2,4][2,4]。
  • 对于 S=[1,2,1,3]S=[1,2,1,3],Simon 将选择区间 [1,1][1,1]、[2,2][2,2] 和 [3,4][3,4]。
  • 对于 S=[1,2,3,1]S=[1,2,3,1],Simon 将选择区间 [1,1][1,1]、[2,2][2,2]、[3,3][3,3] 和 [4,4][4,4]。
  • 对于 S=[1,3,2,1]S=[1,3,2,1],Simon 将选择区间 [1,4][1,4]。
  • 对于 S=[2,1,1,3]S=[2,1,1,3],Simon 将选择区间 [1,2][1,2] 和 [3,4][3,4]。
  • 对于 S=[2,1,3,1]S=[2,1,3,1],Simon 将选择区间 [1,2][1,2]、[3,3][3,3] 和 [4,4][4,4]。
  • 对于 S=[3,2,1,1]S=[3,2,1,1],Simon 将选择区间 [1,3][1,3] 和 [4,4][4,4]。

输入解题思路,AI测评打分。不知道怎么写?

首页