QOJ.ac

QOJ

Límite de tiempo: 6 s Límite de memoria: 1024 MB Puntuación total: 100

#1450. 噪声

Estadísticas

你想编写一个应用程序,通过录制一段短小的歌曲片段来识别它是哪首歌。在你的应用中,音频被表示为每 100 微秒音频波振幅的数组(即“脉冲编码调制 PCM”原始音频格式)。

对于本题,我们关注的情况是:有一首由数组 $a_1, a_2, \dots, a_n$ 表示的完整歌曲,以及一段由数组 $b_1, b_2, \dots, b_m$ 表示的录制片段。你现在希望计算录制片段 $b$ 在歌曲 $a$ 中出现了多少次。

然而,你需要考虑到用于录制 $b$ 的麦克风并不总是完美的——可能会引入一些噪声。具体来说,如果你的麦克风测量值为 $b_i$,那么真实值可能是 $b_i - 1$、$b_i$ 或 $b_i + 1$。注意,录制过程中不同位置可能存在不同的噪声。例如,如果真实数组是 $[1, 2, 3, 4]$,那么录制得到的数组可能是 $[2, 2, 2, 5]$。

因此,你需要计算在考虑这种噪声的情况下,$b$ 在 $a$ 中可能出现的次数。具体而言,给定长度分别为 $n$ 和 $m$ 的数组 $a$ 和 $b$,你需要计算有多少个偏移量 $x$ ($0 \le x \le n - m$) 满足对于所有 $1 \le i \le m$,都有 $b_i - 1 \le a_{x+i} \le b_i + 1$。

输入格式

  • 第一行包含两个空格分隔的整数 $n$ 和 $m$ ($1 \le m \le n \le 400\,000$)。
  • 下一行包含 $n$ 个整数:$a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000\,000$)。
  • 最后一行包含 $m$ 个整数:$b_1, b_2, \dots, b_m$ ($1 \le b_i \le 1\,000\,000$)。

输出格式

输出一个整数,即问题的答案。

样例

样例输入 1

5 3
1 2 3 4 5
2 3 4

样例输出 1

3

样例输入 2

5 2
100 199 300 201 299
200 300

样例输出 2

2

样例输入 3

3 3
1 1 1
1 2 3

样例输出 3

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.