QOJ.ac

QOJ

حد الوقت: 3.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#17158. 回文

الإحصائيات

在本题中,我们考虑由二元字符集 $\{a, b\}$ 组成的字符串。如果一个字符串从左往右读和从右往左读是相同的,则称其为回文串。例如,字符串 aabababbab 是回文串,但 abab 不是。

有一个未知的、长度为 $N$ 且仅包含字符 $\{a, b\}$ 的字符串 $s$。我们只知道它长度为 $a_1, \dots, a_n$ 的前缀(即前缀子串)是回文串。有多少种方式可以还原出字符串 $s$?答案可能非常大,你只需要输出其模 $m$ 的余数。

注意,除了长度为 $a_1, \dots, a_n$ 的前缀外,所求的字符串 $s$ 可能还拥有其他也是回文串的前缀。

输入格式

第一行包含三个整数 $N$、$n$ 和 $m$($1 \le N \le 10^{18}$,$1 \le n \le 500\,000$,$2 \le m \le 10^9$),分别表示字符串的长度、字符串的回文前缀数量,以及用于计算结果的模数。

第二行包含一个严格递增的、由 $n$ 个整数组成的序列 $a_1, a_2, \dots, a_n$(其中 $1 \le a_i \le N$),表示所求字符串的回文前缀的长度。

输出格式

输出应包含一个非负整数,即长度为 $N$ 且对于每个长度 $a_1, \dots, a_n$ 都拥有回文前缀的字符串的数量模 $m$ 的余数。

样例

输入样例 1

10 3 100
2 5 9

输出样例 1

8

说明

有 8 个长度为 10 的字符串,其长度为 2、5 和 9 的前缀都是回文串:

  1. aaaaaaaaaa
  2. aaaaaaaaab
  3. aabaaabaaa
  4. aabaaabaab
  5. bbabbbabba
  6. bbabbbabbb
  7. bbbbbbbbba
  8. bbbbbbbbbb

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1057EditorialOpen题解jiangly2026-02-19 13:13:56View

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.