A8584 | Two Permutations
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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_{i1}$ , $a_{2}=b_{i2}$ , $...$ , $a_{n}=b_{in}$ , 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.
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_{i1}$ , $a_{2}=b_{i2}$ , $...$ , $a_{n}=b_{in}$ , 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.
输入格式
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.
输出格式
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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted