Twice Subsequence

AtCoder
IDarc195_a
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
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$.
API Response (JSON)
{
  "problem": {
    "name": "Twice Subsequence",
    "description": {
      "content": "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 ta",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc195_a"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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 ta...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments