AT_arc223_f.Zonal Score Maximization

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Define the score of a positive integer sequence with length 22 or more as the sum of its maximum and minimum values.
For a positive integer sequence AA of length 22 or more, let f(A)f(A) be the maximum possible value of the total score of the contiguous subsequences when AA is divided into one or more contiguous subsequences each of length 22 or more.
More formally, for a positive integer KK, let f(A)f(A) be the maximum possible value of ∑k=1K(max⁡(Bk)+min⁡(Bk))\sum_{k=1}^{K}\left(\max(B_k)+\min(B_k)\right) when concatenating KK positive integer sequences B1,B2,…,BKB_1, B_2, \dots, B_K, each of length 22 or more, in this order yields the same sequence as AA.

You are given an integer sequence QQ of length NN where each element is either an integer between 11 and NN inclusive or −1-1, and a positive integer XX.
Find the total number, modulo 998244353998244353, of permutations P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N) of (1,2,…,N)(1,2,\dots,N) satisfying all of the following conditions.

  • For i=1,2,…,Ni=1,2,\dots,N, if Qi≠−1Q_i \neq -1 then Pi=QiP_i=Q_i.
  • f(P)=Xf(P)=X

Solve TT test cases per input.

定义一个长度至少为 22 的正整数序列的得分为其最大值与最小值之和。
对于一个长度至少为 22 的正整数序列 AA,令 f(A)f(A) 表示将 AA 划分为一个或多个长度均至少为 22 的连续子序列时,这些子序列的得分总和所能达到的最大值。
更严格地,对任意正整数 KK,令 f(A)f(A) 为如下表达式的最大可能值:∑k=1K(max⁡(Bk)+min⁡(Bk))\sum_{k=1}^{K}\left(\max(B_k)+\min(B_k)\right),其中 B1,B2,…,BKB_1, B_2, \dots, B_K 是 KK 个长度均至少为 22 的正整数序列,且将它们按顺序拼接后得到的序列恰好等于 AA。

给定一个长度为 NN 的整数序列 QQ,其中每个元素要么是介于 11 到 NN(含)之间的整数,要么为 −1-1;另给定一个正整数 XX。
求满足以下所有条件的排列 P=(P1,P2,…,PN)P=(P_1,P_2,\dots,P_N)(即 (1,2,…,N)(1,2,\dots,N) 的一个排列)的总数,结果对 998244353998244353 取模:

  • 对每个 i=1,2,…,Ni=1,2,\dots,N,若 Qi≠−1Q_i \neq -1,则 Pi=QiP_i=Q_i;
  • f(P)=Xf(P)=X。

每组输入包含 TT 个测试用例,需全部求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case caset\mathrm{case}_t is given in the following format:

NN XX
Q1Q_1 Q2Q_2 …\dots QNQ_N

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例 caset\mathrm{case}_t 按以下格式给出:

NN XX
Q1Q_1 Q2Q_2 …\dots QNQ_N

输出格式

Output the answers over a total of TT lines. The tt-th line should contain the answer for the tt-th test case.

在总共 TT 行中输出答案。第 tt 行应包含第 tt 个测试用例的答案。

输入输出样例

  • 输入#1

    3
    3 4
    2 -1 -1
    4 10
    1 3 4 2
    9 42
    -1 -1 -1 -1 -1 -1 -1 -1 -1

    输出#1

    2
    1
    155520

说明/提示

Sample 1 Explanation:
For the first test case, the permutations PP satisfying the first condition are these two: (2,1,3)(2,1,3) and (2,3,1)(2,3,1). In either case, the only way to divide PP into contiguous subsequences each of length 22 or more is to take PP itself as a single contiguous subsequence. The total score in that case is 3+1=43+1=4, so f(P)=4f(P)=4.
For the second test case, dividing P=(1,3,4,2)P=(1,3,4,2) into (1,3)(1,3) and (4,2)(4,2) gives a total score of 1010, which cannot be exceeded, so f(P)=10f(P)=10.

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤1052 \leq N \leq 10^5
  • 1≤X≤10181 \leq X \leq 10^{18}
  • Qi=−1Q_i=-1 or 1≤Qi≤N1 \leq Q_i \leq N
  • If Qi≠−1Q_i \neq -1 and Qj≠−1Q_j \neq -1, then Qi≠Qj  (i≠j)Q_i \neq Q_j\;(i \neq j).
  • The sum of NN over all test cases is at most 10510^5.
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,满足第一个条件的排列 PP 有两个:(2,1,3)(2,1,3) 和 (2,3,1)(2,3,1)。在这两种情况下,将 PP 划分为若干长度均不小于 22 的连续子序列的唯一方式是将 PP 整体作为一个连续子序列。此时总得分为 3+1=43+1=4,因此 f(P)=4f(P)=4。
对于第二个测试用例,将 P=(1,3,4,2)P=(1,3,4,2) 划分为 (1,3)(1,3) 和 (4,2)(4,2) 可得到总得分 1010,该得分无法被超越,因此 f(P)=10f(P)=10。

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 2≤N≤1052 \leq N \leq 10^5
  • 1≤X≤10181 \leq X \leq 10^{18}
  • Qi=−1Q_i=-1 或 1≤Qi≤N1 \leq Q_i \leq N
  • 若 Qi≠−1Q_i \neq -1 且 Qj≠−1Q_j \neq -1,则 Qi≠Qj  (i≠j)Q_i \neq Q_j\;(i \neq j)。
  • 所有测试用例的 NN 之和不超过 10510^5。
  • 所有输入值均为整数。

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

首页