#B3691. Fierce Cutting
Fierce Cutting
Fierce Cutting
Given a sequence (a_1, a_2, \dots, a_n) of length (n) and (m) distinct integers (b_1, b_2, \dots, b_m), you are asked to perform a "fierce cutting" on the sequence with respect to the numbers in the (b) list. For an index (i) in ([1,n]), if there exists an integer (j) in ([1,m]) such that (a_i = b_j), then index (i) is called a cutting point. For each cutting point, remove the element at that position and split the current segment into two parts at that position. After performing all possible fierce cuttings, count the number of segments (fragments) left. A fragment is defined as a non-empty contiguous subsequence from the remaining elements. Note that if the cut is at the very beginning or the very end of the sequence, the resulting empty part is not counted as a fragment.
For better understanding, please refer to the sample cases and their explanations.
inputFormat
The first line contains two integers (n) and (m) ((1 \leq n \leq 10^5), (1 \leq m \leq n)). The second line contains (n) integers (a_1, a_2, \dots, a_n). The third line contains (m) distinct integers (b_1, b_2, \dots, b_m).
outputFormat
Output a single integer representing the number of fragments (non-empty segments) after performing all the fierce cuttings.
sample
7 2
1 2 3 2 4 5 2
2 5
3