QOJ.ac

QOJ

Limite de temps : 1.5 s Limite de mémoire : 128 MB Points totaux : 100

#13325. 多彩链

Statistiques

小 Bytie 喜欢玩彩色链条。他已经收集了相当多令人印象深刻的链条,其中一些他比其他的更喜欢。每条链条都由一定数量的彩色链环组成。Byteasar 注意到 Bytie 的审美感非常精确。事实证明,如果链条的一个连续片段恰好包含 $l_{1}$ 个颜色为 $c_{1}$ 的链环,$l_{2}$ 个颜色为 $c_{2}$ 的链环,……,$l_{m}$ 个颜色为 $c_{m}$ 的链环,并且不包含其他颜色的链环,那么 Bytie 就会认为这个片段是“漂亮的”。一条链条的吸引力在于它所包含的“漂亮”连续片段的数量。通过反复试验,Byteasar 确定了 $c_{1},…,c_{m}$ 和 $l_{1},…,l_{m}$ 的值。现在他想买一条新链条,因此请求你编写一个程序来辅助他购物。

输入格式

标准输入的第一行包含两个整数 $n$ 和 $m$ ($1 \le m \le n \le 1\,000\,000$),用空格分隔。它们分别是链条的长度和“漂亮”片段描述的长度。第二行包含 $m$ 个整数 $l_{1},…,l_{m}$ ($1 \le l_{i} \le n$),用空格分隔。第三行包含 $m$ 个整数 $c_{1},…,c_{m}$ ($1 \le c_{i} \le n$, $c_{i} \neq c_{j}$ 当 $i \neq j$ 时),用空格分隔。序列 $l_{1},…,l_{m}$ 和 $c_{1},…,c_{m}$ 定义了链条的“漂亮”片段——它必须恰好包含 $l_{i}$ 个颜色为 $c_{i}$ 的链环。第四行包含 $n$ 个整数 $a_{1},…,a_{n}$ ($1 \le a_{i} \le n$),用空格分隔,表示链条上连续链环的颜色。

输出格式

你的程序应在标准输出的第一行(也是唯一一行)打印一个整数,即链条中“漂亮”连续片段的数量。

样例

输入 1

7 3
2 1 1
1 2 3
4 2 1 3 1 2 5

输出 1

2

说明

该链条中两个“漂亮”的片段分别是 2, 1, 3, 1 和 1, 3, 1, 2。

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.