CF213E.Two Permutations
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Rubik is very keen on number permutations.
A permutation a with length n is a sequence, consisting of n different numbers from 1 to n. Element number i (1 ≤ i ≤ n) of this permutation will be denoted as a__i.
Furik decided to make a present to Rubik and came up with a new problem on permutations. Furik tells Rubik two number permutations: permutation a with length n and permutation b with length m. Rubik must give an answer to the problem: how many distinct integers d exist, such that sequence c (_c_1 = _a_1 + d, _c_2 = _a_2 + d, ..., c__n = a__n + d) of length n is a subsequence of b.
Sequence a is a subsequence of sequence b, if there are such indices _i_1, _i_2, ..., i__n (1 ≤ _i_1 < _i_2 < ... < i__n ≤ m), that _a_1 = _b__i_1, _a_2 = _b__i_2, ..., a__n = b__i__n, where n is the length of sequence a, and m is the length of sequence b.
You are given permutations a and b, help Rubik solve the given problem.
鲁比克对数字排列非常着迷。
一个长度为 $ n $ 的排列 $ a $ 是由 $ 1 $ 到 $ n $ 中互不相同的 $ n $ 个数组成的序列。该排列中第 $ i $ 个元素($ 1 \leq i \leq n $)记作 $ a_i $。
弗里克决定送给鲁比克一份礼物,并为此构思了一个关于排列的新问题。弗里克告诉鲁比克两个数字排列:长度为 $ n $ 的排列 $ a $ 和长度为 $ m $ 的排列 $ b $。鲁比克需要回答如下问题:有多少个互不相同的整数 $ d $,使得长度为 $ n $ 的序列 $ c $(其中 $ c_1 = a_1 + d,\ c_2 = a_2 + d,\ \dots,\ c_n = a_n + d $)是 $ b $ 的一个子序列。
序列 $ a $ 是序列 $ b $ 的子序列,当且仅当存在下标 $ i_1,\ i_2,\ \dots,\ i_n $(满足 $ 1 \leq i_1 < i_2 < \dots < i_n \leq m $),使得 $ a_1 = b_{i_1},\ a_2 = b_{i_2},\ \dots,\ a_n = b_{i_n} $,其中 $ n $ 是序列 $ a $ 的长度,$ m $ 是序列 $ b $ 的长度。
现给出排列 $ a $ 和 $ b $,请帮助鲁比克解决该问题。
输入格式
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 200000) — the sizes of the given permutations. The second line contains n distinct integers — permutation a, the third line contains m distinct integers — permutation b. Numbers on the lines are separated by spaces.
第一行包含两个整数 n 和 m(1≤n≤m≤200000)—— 分别表示给定排列的大小。第二行包含 n 个互不相同的整数——排列 a;第三行包含 m 个互不相同的整数——排列 b。每行中的数字以空格分隔。
输出格式
On a single line print the answer to the problem.
在一行中输出问题的答案。
输入输出样例
输入#1
1 1 1 1
输出#1
1
输入#2
1 2 1 2 1
输出#2
2
输入#3
3 3 2 3 1 1 2 3
输出#3
0
输入解题思路,AI测评打分。不知道怎么写?