QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

对一个由正整数组成的数组 $x$ 进行以下两个步骤,称为一次操作:

  1. 选择 $x$ 中任意两个相邻的元素,将其中一个减少 1,并将另一个设为 0。
  2. 从 $x$ 中移除所有的 0。

我们称 $x$ 是神秘的(mystic),当且仅当它可以在有限次(可能为零次)操作后被转化为一个空序列。

给你一个由 $n$ 个整数组成的数组 $a$,以及一个整数 $m$。$a$ 中的每个元素要么是 $1$ 到 $m$ 之间的整数,要么是 $-1$。你的任务是将 $a$ 中所有出现的 $-1$ 替换为 $1$ 到 $m$ 之间的任意整数。

求在替换后可以得到的不同神秘数组 $a$ 的数量。由于答案可能非常大,请将其对 $10^9 + 7$ 取模后输出。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$($2 \le n \le 10^6$,$1 \le m \le 10^8$)。

输入的第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \le a_i \le m$ 或 $a_i = -1$)。

输出格式

输出一个整数,表示可以得到的不同神秘序列 $a$ 的数量,模 $10^9 + 7$ 的结果。

样例

输入样例 1

2 2
-1 -1

输出样例 1

3

输入样例 2

6 10
-1 -1 -1 -1 1 7

输出样例 2

9125

说明

在第一个样例中,数组 $a$ 为 $[-1, -1]$。通过替换两个 $-1$,一种可能的结果是 $[1, 2]$。在这种情况下,我们选择两个相邻的数:将第一个数减少 1,并将第二个数设为 0,得到 $[0, 0]$。移除所有 0 后,序列变为空。因此,$[1, 2]$ 是一个神秘序列。

类似地,如果我们用 $[1, 1]$ 或 $[2, 1]$ 替换 $-1$,这两个序列也都可以被化为空。因此,不同的神秘序列总数为 3。

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.