QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#16273. Third grader's task

统计

小男孩 Tyler 在看厨房的冰箱时,注意到了一些带有字符的磁贴,它们可以排成一个字符串 $s$。

Tyler 喜欢字符串,尤其是那些字典序小于字符串 $t$ 的字符串。在玩了冰箱上的磁贴后,他想知道,通过重新排列字符串 $s$ 的字符,可以组成多少个不同的字符串,使得结果字符串的字典序小于字符串 $t$。Tyler 才上三年级,所以他无法回答这个问题。请帮助他计算字符串 $s$ 的字符排列中,字典序小于字符串 $t$ 的不同排列个数。

我们称字符串 $x$ 的字典序小于字符串 $y$,如果满足以下条件之一:

  • 存在一个位置 $m$,该位置在两个字符串中都存在,使得在第 $m$ 个字符之前两个字符串相等,且字符串 $x$ 的第 $m$ 个字符小于字符串 $y$ 的第 $m$ 个字符。
  • 字符串 $x$ 是字符串 $y$ 的前缀。

由于答案可能非常大,请将其对 $998\,244\,353$ 取模后输出。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($1 \le n, m \le 200\,000$) —— 字符串 $s$ 和 $t$ 的长度。

第二行包含 $n$ 个整数 $s_1, s_2, s_3 \dots s_n$ ($1 \le s_i \le 200\,000$) —— 字符串 $s$ 的字符。

第三行包含 $m$ 个整数 $t_1, t_2, t_3 \dots t_m$ ($1 \le t_i \le 200\,000$) —— 字符串 $t$ 的字符。

输出格式

输出单个整数 —— 通过重新排列字符串 $s$ 的字符可以组成的字典序小于 $t$ 的不同字符串个数,对 $998\,244\,353$ 取模。

样例

输入样例 1

3 4
1 2 2
2 1 2 1

输出样例 1

2

输入样例 2

4 4
1 2 3 4
4 3 2 1

输出样例 2

23

输入样例 3

4 3
1 1 1 2
1 1 2

输出样例 3

1

说明

在第一个样例中,我们应该统计字符串 [1 2 2][2 1 2]。字符串 [2 2 1] 的字典序大于字符串 [2 1 2 1],所以我们不统计它。

在第二个样例中,除了 [4 3 2 1] 之外,我们应该统计所有字符串,所以答案是 $4! - 1 = 23$。

在第三个样例中,我们应该只统计字符串 [1 1 1 2]

子任务

该题的测试集包含 6 个测试组。只有当你的程序通过该组的所有测试点以及所有要求的组时,你才能获得该组的分数。离线评测(Offline-evaluation)意味着你不会立即获得该组的反馈,只能在比赛结束后看到结果。请注意,通过所有样例测试点并不是必需的。

子任务 分值 附加限制 $n, m$ 附加限制 $s_i, t_i$ 依赖的子任务 备注
0 0 样例测试。
1 16 $n, m \le 10$ $s_i, t_i \le 10$ 0
2 15 $s_i, t_i \le 2$
3 11 $s_i, t_i \le 20$ 0 – 2
4 13 $s_i, t_i \le 200$ 0 – 3
5 12 在每个字符串中,所有字符各自互不相同。
6 33 0 – 5 离线评测。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.