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 2 or more as the sum of its maximum and minimum values.
For a positive integer sequence A of length 2 or more, let f(A) be the maximum possible value of the total score of the contiguous subsequences when A is divided into one or more contiguous subsequences each of length 2 or more.
More formally, for a positive integer K, let f(A) be the maximum possible value of ∑k=1K(max(Bk)+min(Bk)) when concatenating K positive integer sequences B1,B2,…,BK, each of length 2 or more, in this order yields the same sequence as A.
You are given an integer sequence Q of length N where each element is either an integer between 1 and N inclusive or −1, and a positive integer X.
Find the total number, modulo 998244353, of permutations P=(P1,P2,…,PN) of (1,2,…,N) satisfying all of the following conditions.
- For i=1,2,…,N, if Qi=−1 then Pi=Qi.
- f(P)=X
Solve T test cases per input.
定义一个长度至少为 2 的正整数序列的得分为其最大值与最小值之和。
对于一个长度至少为 2 的正整数序列 A,令 f(A) 表示将 A 划分为一个或多个长度均至少为 2 的连续子序列时,这些子序列的得分总和所能达到的最大值。
更严格地,对任意正整数 K,令 f(A) 为如下表达式的最大可能值:∑k=1K(max(Bk)+min(Bk)),其中 B1,B2,…,BK 是 K 个长度均至少为 2 的正整数序列,且将它们按顺序拼接后得到的序列恰好等于 A。
给定一个长度为 N 的整数序列 Q,其中每个元素要么是介于 1 到 N(含)之间的整数,要么为 −1;另给定一个正整数 X。
求满足以下所有条件的排列 P=(P1,P2,…,PN)(即 (1,2,…,N) 的一个排列)的总数,结果对 998244353 取模:
- 对每个 i=1,2,…,N,若 Qi=−1,则 Pi=Qi;
- f(P)=X。
每组输入包含 T 个测试用例,需全部求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case caset is given in the following format:
N X
Q1 Q2 … QN
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例 caset 按以下格式给出:
N X
Q1 Q2 … QN
输出格式
Output the answers over a total of T lines. The t-th line should contain the answer for the t-th test case.
在总共 T 行中输出答案。第 t 行应包含第 t 个测试用例的答案。
输入输出样例
输入#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 P satisfying the first condition are these two: (2,1,3) and (2,3,1). In either case, the only way to divide P into contiguous subsequences each of length 2 or more is to take P itself as a single contiguous subsequence. The total score in that case is 3+1=4, so f(P)=4.
For the second test case, dividing P=(1,3,4,2) into (1,3) and (4,2) gives a total score of 10, which cannot be exceeded, so f(P)=10.
Constraints
- 1≤T≤105
- 2≤N≤105
- 1≤X≤1018
- Qi=−1 or 1≤Qi≤N
- If Qi=−1 and Qj=−1, then Qi=Qj(i=j).
- The sum of N over all test cases is at most 105.
- All input values are integers.
样例 1 解释:
对于第一个测试用例,满足第一个条件的排列 P 有两个:(2,1,3) 和 (2,3,1)。在这两种情况下,将 P 划分为若干长度均不小于 2 的连续子序列的唯一方式是将 P 整体作为一个连续子序列。此时总得分为 3+1=4,因此 f(P)=4。
对于第二个测试用例,将 P=(1,3,4,2) 划分为 (1,3) 和 (4,2) 可得到总得分 10,该得分无法被超越,因此 f(P)=10。
约束条件
- 1≤T≤105
- 2≤N≤105
- 1≤X≤1018
- Qi=−1 或 1≤Qi≤N
- 若 Qi=−1 且 Qj=−1,则 Qi=Qj(i=j)。
- 所有测试用例的 N 之和不超过 105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?