logo AlgoBeat OnlineJudge
登录 注册

#202630. [POI 2013] LAN-Colorful Chain

内存限制:125 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Little Bytie loves to play with colorful chains.

He already has quite an impressive collection, and some of them he likes more than the others.

Each chain consists of a certain number of colorful links.

Byteasar has noticed that Bytie's sense of aesthetics is very precise.

It turns out that Bytie finds a contiguous fragment of a chain nice if it contains exactly links of color links of color links of color , and moreover it contains no links of other colors.

A chain's appeal is its number of (contiguous) fragments that are nice.

By trial and error, Byteasar has determined the values and .

Now he would like to buy a new chain, and therefore asks you to write a program to aid him in shopping.

给定一个长度为 的序列 和 个条件(每个条件中包含键 和值 ),要求找出满足下列条件的子串的数量并输出:

  • 对于 个条件中存在的 (),子串中包含恰好 个 ;

  • 对于 个条件中不存在的键值,子串中不包含它。

输入格式

The first line of the standard input gives two integers, and (), separated by a single space.

These are the length of the chain and the length of a nice fragment's description.

The second line gives integers, (), separated by single spaces.

The third line gives integers, (, for ), also separated by single spaces.

The sequences and define a nice fragment of a chain - it has to contain exactly links of color .

The fourth line gives integers, (), separated by single spaces, that are the colors of successive links of the chain.

In tests worth 50% of total points the constraint holds in addition.

先输入 和 ,再输入 个条件的 ,然后输入 个条件的 ,最后输入 。

输出格式

Your program is to print a single integer, the number of nice contiguous fragments in the chain, to the first and only line of the standard output.

输出一行一个整数,表示满足条件的子串数量。

样例

样例输入 1

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

样例输出 1

2

数据范围与提示

数据范围:

对于 的数据,,。