| TheForces Round #28 (Epic-Forces) |
|---|
| Finished |
You're given an array $$$a$$$ of size $$$n$$$ and an array $$$b$$$ of size $$$m$$$.
Find the minimum $$$k$$$ such that $$$a$$$ is a subsequence$$$^\dagger$$$ of $$$dup(b, k)$$$. If there's no such $$$k$$$, output $$$-1$$$ instead.
Here $$$dup(b,k)=[b_1,b_2,\ldots,b_m,b_1,b_2,\ldots,b_m,\ldots]$$$($$$k$$$ times). More formally, $$$dup(b,k)$$$ is an array $$$x$$$ of length $$$m \cdot k$$$, where $$$x_i = b _{(i-1)\ mod\ m\ +\ 1}$$$ for all $$$1 \le i \le m \cdot k$$$.
$$$^\dagger$$$A subsequence of a sequence is a sequence that is formed by selecting zero or more elements from the original sequence while maintaining the relative order of the selected elements.
The first line contains a single integer $$$t(1 \le t\le 10^4)$$$ — the number of test cases.
The first line of each test case contains two numbers $$$n,m(1 \le n,m\le 2\times10^5)$$$.
The second line of each test case contains $$$n$$$ numbers $$$a_1,a_2,\ldots,a_n(1 \le a_i\le max(n,m))$$$.
The third line of each test case contains $$$m$$$ numbers $$$b_1,b_2,\ldots,b_m(1 \le b_i\le max(n,m))$$$.
It is guaranteed that the sum of $$$n$$$ for all tests does not exceed $$$2\times 10^5$$$, and the sum of $$$m$$$ for all tests does not exceed $$$2\times 10^5$$$.
For each test case, output the minimum $$$k$$$. If there's no suitable $$$k$$$, output $$$-1$$$ instead.
42 11 123 42 1 21 2 1 14 41 2 3 44 3 2 118 1711 17 1 5 16 17 16 18 16 13 16 2 9 16 16 11 5 13 16 18 18 11 5 13 16 1 14 17 9 16 2 17 5 13
-1 2 4 7
| Name |
|---|


