2506: Sequence

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:2 解决:1

题目描述

Losanto has a sequence {a1,a2,…,an} with n positive integers. Superman has some positive integer sequences with different size. Losanto wants to know the total occurrences of every sequence Superman has in Losanto's sequence (the occurrences are allowed to overlap).
We say one sequence B occurs in another sequence A if there is a contiguous subsequence of A that is the same as B after add an integer.
For example A={1,2,3,5},B={2,3} then B occurs two times in A. The occurrences are {1,2}and{2,3} . And the addition is -1 and 0.

输入

There are multiple test cases. (No more than 20 cases)
For each test case:The first line contains two integer n and m (1n,m10000), indicating the size of Losanto's sequence and the number of sequences Superman has. In the next line, there are integers, a1,a2,…,an, indicating Losanto's sequence. In the following m lines, each starts with an integer ki(1ki10000) - the size of the sequence. Then ki space separated positive integers follow, indicating the sequence.
The total sum of ki is less than or equal to 100000. Other integers are between 1 and 10000, inclusive.

输出

   For each case:

    One line with A number indicate that the sum of occurs times.

样例输入 复制

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

样例输出 复制

3

来源/分类