A13297 | Permutation Partitions
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$ and an integer $k$ , such that $1 \leq k \leq n$ . A permutation means that every number from $1$ to $n$ is contained in $p$ exactly once.
Let's consider all partitions of this permutation into $k$ disjoint segments. Formally, a partition is a set of segments $\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\}$ , such that:
- $1 \leq l_i \leq r_i \leq n$ for all $1 \leq i \leq k$ ;
- For all $1 \leq j \leq n$ there exists exactly one segment $[l_i, r_i]$ , such that $l_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 $\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}$ , for all possible partitions of the permutation into $k$ 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\,353$ .
Let's consider all partitions of this permutation into $k$ disjoint segments. Formally, a partition is a set of segments $\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\}$ , such that:
- $1 \leq l_i \leq r_i \leq n$ for all $1 \leq i \leq k$ ;
- For all $1 \leq j \leq n$ there exists exactly one segment $[l_i, r_i]$ , such that $l_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 $\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}$ , for all possible partitions of the permutation into $k$ 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\,353$ .
输入格式
The first line contains two integers, $n$ and $k$ ( $1 \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 $n$ different integers $p_1, p_2, \ldots, p_n$ ( $1 \leq p_i \leq n$ ) — the given permutation.
The second line contains $n$ different integers $p_1, p_2, \ldots, p_n$ ( $1 \leq p_i \leq n$ ) — the given permutation.
输出格式
Print two integers — the maximum possible partition value over all partitions of the permutation into $k$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $998\,244\,353$ .
Please note that you should only find the second value modulo $998\,244\,353$ .
Please note that you should only find the second value modulo $998\,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 = 2$ , there exists only two valid partitions: $\{[1, 1], [2, 3]\}$ and $\{[1, 2], [3, 3]\}$ . For each partition, the partition value is equal to $2 + 3 = 5$ . So, the maximum possible value is $5$ and the number of partitions is $2$ .
In the third test, for $k = 3$ , the partitions with the maximum possible partition value are $\{[1, 2], [3, 5], [6, 7]\}$ , $\{[1, 3], [4, 5], [6, 7]\}$ , $\{[1, 4], [5, 5], [6, 7]\}$ , $\{[1, 2], [3, 6], [7, 7]\}$ , $\{[1, 3], [4, 6], [7, 7]\}$ , $\{[1, 4], [5, 6], [7, 7]\}$ . For all of them, the partition value is equal to $7 + 5 + 6 = 18$ .
The partition $\{[1, 2], [3, 4], [5, 7]\}$ , however, has the partition value $7 + 3 + 6 = 16$ . This is not the maximum possible value, so we don't count it.
In the third test, for $k = 3$ , the partitions with the maximum possible partition value are $\{[1, 2], [3, 5], [6, 7]\}$ , $\{[1, 3], [4, 5], [6, 7]\}$ , $\{[1, 4], [5, 5], [6, 7]\}$ , $\{[1, 2], [3, 6], [7, 7]\}$ , $\{[1, 3], [4, 6], [7, 7]\}$ , $\{[1, 4], [5, 6], [7, 7]\}$ . For all of them, the partition value is equal to $7 + 5 + 6 = 18$ .
The partition $\{[1, 2], [3, 4], [5, 7]\}$ , however, has the partition value $7 + 3 + 6 = 16$ . This is not the maximum possible value, so we don't count it.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted