CF1326C.Permutation Partitions

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a permutation p1,p2,…,pnp_1, p_2, \ldots, p_n of integers from 11 to nn and an integer kk, such that 1≤k≤n1 \leq k \leq n. A permutation means that every number from 11 to nn is contained in pp exactly once.

Let's consider all partitions of this permutation into kk disjoint segments. Formally, a partition is a set of segments [l1,r1],[l2,r2],…,[lk,rk]{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]}, such that:

  • 1≤li≤ri≤n1 \leq l_i \leq r_i \leq n for all 1≤i≤k1 \leq i \leq k;
  • For all 1≤j≤n1 \leq j \leq n there exists exactly one segment [li,ri][l_i, r_i], such that li≤j≤ril_i \leq j \leq r_i.

Two partitions are different if there exists a segment that lies in one partition but not the other.

Let's calculate the partition value, defined as ∑i=1kmax⁡li≤j≤ripj\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}, for all possible partitions of the permutation into kk disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by 998 244 353998\,244\,353.

给你一个由 11 到 nn 的整数构成的排列 p1,p2,…,pnp_1, p_2, \ldots, p_n,以及一个整数 kk,满足 1≤k≤n1 \leq k \leq n。所谓排列,是指每个从 11 到 nn 的整数在 pp 中恰好出现一次。

考虑该排列的所有划分为 kk 个互不相交段(segments)的方式。形式上,一种划分是一组段 {[l1,r1],[l2,r2],…,[lk,rk]}\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\},满足:

  • 对所有 1≤i≤k1 \leq i \leq k,有 1≤li≤ri≤n1 \leq l_i \leq r_i \leq n;
  • 对所有 1≤j≤n1 \leq j \leq n,存在恰好一个段 [li,ri][l_i, r_i],使得 li≤j≤ril_i \leq j \leq r_i。

若存在某个段属于一个划分但不属于另一个划分,则称这两个划分不同。

对每种将排列划分为 kk 个互不相交段的方式,我们定义其划分值为

∑i=1kmax⁡li≤j≤ripj.\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}.

请找出所有此类划分中可能达到的最大划分值,以及达到该最大值的划分数量。由于该数量可能非常大,请输出它对 998 244 353998\,244\,353 取模的结果。

输入格式

The first line contains two integers, nn and kk (1≤k≤n≤200 0001 \leq k \leq n \leq 200\,000) — the size of the given permutation and the number of segments in a partition.

The second line contains nn different integers p1,p2,…,pnp_1, p_2, \ldots, p_n (1≤pi≤n1 \leq p_i \leq n) — the given permutation.

第一行包含两个整数 nn 和 kk(1≤k≤n≤200 0001 \leq k \leq n \leq 200\,000)—— 分别表示给定排列的长度以及划分中区间的个数。

第二行包含 nn 个互不相同的整数 p1,p2,…,pnp_1, p_2, \ldots, p_n(1≤pi≤n1 \leq p_i \leq n)—— 给定的排列。

输出格式

Print two integers — the maximum possible partition value over all partitions of the permutation into kk disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo 998 244 353998\,244\,353.

Please note that you should only find the second value modulo 998 244 353998\,244\,353.

输出两个整数:在将该排列划分为 kk 个互不相交的段的所有划分方案中,划分值的最大可能值;以及使得划分值等于该最大可能值的划分方案数目(对 998 244 353998\,244\,353 取模)。

请注意,你只需将第二个数值对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    3 2
    2 1 3

    输出#1

    5 2
  • 输入#2

    5 5
    2 1 5 3 4

    输出#2

    15 1
  • 输入#3

    7 3
    2 7 3 1 5 4 6

    输出#3

    18 6

说明/提示

In the first test, for k=2k = 2, there exists only two valid partitions: [1,1],[2,3]{[1, 1], [2, 3]} and [1,2],[3,3]{[1, 2], [3, 3]}. For each partition, the partition value is equal to 2+3=52 + 3 = 5. So, the maximum possible value is 55 and the number of partitions is 22.

In the third test, for k=3k = 3, the partitions with the maximum possible partition value are [1,2],[3,5],[6,7]{[1, 2], [3, 5], [6, 7]}, [1,3],[4,5],[6,7]{[1, 3], [4, 5], [6, 7]}, [1,4],[5,5],[6,7]{[1, 4], [5, 5], [6, 7]}, [1,2],[3,6],[7,7]{[1, 2], [3, 6], [7, 7]}, [1,3],[4,6],[7,7]{[1, 3], [4, 6], [7, 7]}, [1,4],[5,6],[7,7]{[1, 4], [5, 6], [7, 7]}. For all of them, the partition value is equal to 7+5+6=187 + 5 + 6 = 18.

The partition [1,2],[3,4],[5,7]{[1, 2], [3, 4], [5, 7]}, however, has the partition value 7+3+6=167 + 3 + 6 = 16. This is not the maximum possible value, so we don't count it.

在第一个测试用例中,当 k=2k = 2 时,仅存在两种合法划分:[1,1],[2,3]{[1, 1], [2, 3]} 和 [1,2],[3,3]{[1, 2], [3, 3]}。对每种划分,其划分值均为 2+3=52 + 3 = 5。因此,最大可能的划分值为 55,且划分方案总数为 22。

在第三个测试用例中,当 k=3k = 3 时,具有最大可能划分值的划分有:[1,2],[3,5],[6,7]{[1, 2], [3, 5], [6, 7]}、[1,3],[4,5],[6,7]{[1, 3], [4, 5], [6, 7]}、[1,4],[5,5],[6,7]{[1, 4], [5, 5], [6, 7]}、[1,2],[3,6],[7,7]{[1, 2], [3, 6], [7, 7]}、[1,3],[4,6],[7,7]{[1, 3], [4, 6], [7, 7]}、[1,4],[5,6],[7,7]{[1, 4], [5, 6], [7, 7]}。对所有这些划分,其划分值均为 7+5+6=187 + 5 + 6 = 18。

然而,划分 [1,2],[3,4],[5,7]{[1, 2], [3, 4], [5, 7]} 的划分值为 7+3+6=167 + 3 + 6 = 16,未达到最大可能值,因此不计入统计。

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

首页