CF213E.Two Permutations

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Rubik is very keen on number permutations.

A permutation aa with length nn is a sequence, consisting of nn different numbers from 1 to nn . Element number ii (1<=i<=n)(1<=i<=n) of this permutation will be denoted as aia_{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 aa with length nn and permutation bb with length mm . Rubik must give an answer to the problem: how many distinct integers dd exist, such that sequence cc (c1=a1+d,c2=a2+d,...,cn=an+d)(c_{1}=a_{1}+d,c_{2}=a_{2}+d,...,c_{n}=a_{n}+d) of length nn is a subsequence of bb .

Sequence aa is a subsequence of sequence bb , if there are such indices i1,i2,...,ini_{1},i_{2},...,i_{n} (1<=i_{1}<i_{2}<...<i_{n}<=m) , that a1=bi1a_{1}=b_{i1} , a2=bi2a_{2}=b_{i2} , ...... , an=bina_{n}=b_{in} , where nn is the length of sequence aa , and mm is the length of sequence bb .

You are given permutations aa and bb , help Rubik solve the given problem.

输入格式

The first line contains two integers nn and mm (1<=n<=m<=200000)(1<=n<=m<=200000) — the sizes of the given permutations. The second line contains nn distinct integers — permutation aa , the third line contains mm distinct integers — permutation bb . Numbers on the lines are separated by spaces.

输出格式

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
    
首页