QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#6346. 记录奇偶性

统计

给定一个长度为 $n$ 的排列和一个整数 $k$。

如果一个元素严格大于它之前的所有元素,则称该元素为一个记录(record)。

计算所有恰好包含 $k$ 个记录的子序列的 $(-1)^{len}$ 之和,其中 $len$ 是子序列的长度。由于答案可能很大,请将其对 $998\,244\,353$ 取模。

输入格式

第一行包含两个整数 $n$ 和 $k$ ($1 \le k \le n \le 10^6$)。

第二行包含排列 $p_1, p_2, \dots, p_n$。

输出格式

输出计算结果。

样例

样例输入 1

5 2
4 1 2 5 3

样例输出 1

3

样例输入 2

7 3
1 2 3 4 5 6 7

样例输出 2

998244318

样例输入 3

5 5
2 5 4 1 3

样例输出 3

0

说明

在第二个样例中,所有长度为 $3$ 的子序列都恰好有 $3$ 个记录,且没有其他子序列恰好有 $3$ 个记录,因此总和等于 $(-1)^3 \binom{7}{3} = -35$,即 $998\,244\,318 \pmod{998\,244\,353}$。

在第三个样例中,没有任何子序列恰好有 $5$ 个记录,空集的和为 $0$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.