AtCoder Regular Contest 195 (Div. 2)
A
Twice Subsequence
AtCoder
⌀ 538
原题
←B →
翻译中…

Problem Statement

翻译中…

There is a sequence $A = (A_1,\dots,A_N)$. Determine whether there are at least two subsequences of $A$ that match the sequence $B = (B_1,\dots,B_M)$. Two subsequences are distinguished if they are taken from different positions, even if they coincide as sequences.

翻译中…

Subsequence A subsequence of $A$ is a sequence obtained by removing zero or more elements from $A$ and leaving the remaining elements in their original order.

翻译中…

Constraints

翻译中…
  • $1 \leq M \leq N \leq 2\times 10^5$
  • $1 \leq A_i \leq 10^9$
  • $1 \leq B_i \leq 10^9$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

翻译中…

Output

翻译中…

If there are at least two subsequences of $A$ that match $B$, print Yes. Otherwise, print No.

翻译中…

样例

Input #1
4 2
1 2 1 2
1 2
Output #1
Yes
There are three subsequences of $A$ that match $B$: $(A_1,A_2), (A_1,A_4), (A_3,A_4)$.
Input #2
3 2
1 2 1
1 2
Output #2
No
There is only one subsequence of $A$ that matches $B$: $(A_1,A_2)$.
Input #3
3 2
1 1 2
2 1
Output #3
No
There are no subsequences of $A$ that match $B$.
题目信息
题号
arc195_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。