QOJ.ac

QOJ

時間限制: 3.0 s 記憶體限制: 1024 MB 總分: 100

#10060. 善良度

统计

给定两个整数序列 $A = (a_1, \dots, a_N)$ 和 $B = (b_1, \dots, b_M)$,满足 $N \ge M$,即 $A$ 的长度总是大于或等于 $B$ 的长度。

每个元素都是小于或等于 $L$ 的正整数。序列对 $(A, B)$ 的“优良度”(goodness)定义为满足以下条件的双射(即一一对应的可逆函数)$f: \{1, \dots, L\} \to \{1, \dots, L\}$ 的数量:$B$ 是序列 $(f(a_1), \dots, f(a_N))$ 的连续子序列。

序列的连续子序列是指通过从原序列的开头和结尾移除零个或多个元素而得到的序列。

给定两个序列 $A$ 和 $B$,计算序列对 $(A, B)$ 的优良度。由于答案可能非常大,请将其对 $998\,244\,353$ 取模。

输入格式

第一行包含三个整数:$N$(序列 $A$ 的长度,$1 \le N \le 300\,000$)、$M$(序列 $B$ 的长度,$1 \le M \le N$)和 $L$(允许的最大整数,$1 \le L \le 300\,000$)。

第二行包含 $N$ 个 $1$ 到 $L$ 之间的正整数,表示序列 $A$。

第三行包含 $M$ 个 $1$ 到 $L$ 之间的正整数,表示序列 $B$。

输出格式

输出序列对 $(A, B)$ 的优良度,对 $998\,244\,353$ 取模。

样例

输入 1

9 3 3
1 1 2 3 2 1 1 2 1
1 1 2

输出 1

1

输入 2

1 1 6
2
2

输出 2

120

输入 3

8 3 3
3 2 3 2 3 1 3 1
1 2 1

输出 3

4

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.