CF2151A.Incremental Subarray

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Incremental Subarray

Schtiffles - Marbl

James is learning numbers, and he is having fun writing them on a huge blackboard, from left to right.

  • At the beginning, James writes the number 11.
  • Right after, James writes 11 again, and then 22.
  • Then James writes 11, 22, 33.
  • \ldots
  • In the end, James writes 11, 22, 33, \ldots, nn.

For example, for n=5n = 5, the numbers written by James make the array b=[1,1,2,1,2,3,1,2,3,4,1,2,3,4,5]b = [1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5].

James has a list of favorite numbers a1,a2,,ama_1, a_2, \ldots, a_m, and he wants to calculate how many subarrays of the array bb are equal to a1,a2,,ama_1, a_2, \ldots, a_m. ^{\text{∗}}

James is already sure that a1,a2,,ama_1, a_2, \ldots, a_m is a subarray of bb, so the answer is at least 11.

^{\text{∗}}The subarrays of an array [v1,v2,,vk][v_1, v_2, \ldots, v_k] are generated as follows: for each l,rl, r such that 1lrk1 \leq l \leq r \leq k, the array [vl,vl+1,,vr][v_l, v_{l+1}, \ldots, v_r] is a subarray. So there are k(k+1)/2k(k+1)/2 subarrays in total, and some of them may be equal.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains two integers nn and mm (1n1051 \leq n \leq 10^5, 1m2001 \leq m \leq 200) — the maximum number written by James, and the length of the array a1,a2,,ama_1, a_2, \ldots, a_m.

The second line of each test case contains mm integers a1,a2,,ama_1, a_2, \ldots, a_m (1ai1051 \leq a_i \leq 10^5) — James' favorite numbers.

It is guaranteed that for the given input, the answer is always at least 11.

Note that there are no constraints on the sum of nn and mm over all test cases.

Output

For each test case, output a single line containing an integer: the number of subarrays of the array bb which are equal to a1,a2,,ama_1, a_2, \ldots, a_m.

Note

In the first test case, the blackboard contains the numbers

$$b = [1, 1, 2, 1, 2, 3, 1, 2, 3, 4]$$</p><p>and James has only one favorite number: the number$1$. There are$4$subarrays of$b$equal to$[1]$(highlighted in red):</p><ul> <li>$[\color{red}{1}, 1, 2, 1, 2, 3, 1, 2, 3, 4]$; </li><li>$[1, \color{red}{1}, 2, 1, 2, 3, 1, 2, 3, 4]$; </li><li>$[1, 1, 2, \color{red}{1}, 2, 3, 1, 2, 3, 4]$; </li><li>$[1, 1, 2, 1, 2, 3, \color{red}{1}, 2, 3, 4]$. </li></ul><p>In the second test case, the blackboard contains the numbers</p><p>$$b = [1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]$$</p><p>and James's list of favorite numbers is$[1, 2, 3]$. There are$3$subarrays of$b$equal to$[1, 2, 3]$(highlighted in red):</p><ul> <li>$[1, 1, 2, \color{red}{1, 2, 3}, 1, 2, 3, 4, 1, 2, 3, 4, 5]$; </li><li>$[1, 1, 2, 1, 2, 3, \color{red}{1, 2, 3}, 4, 1, 2, 3, 4, 5]$; </li><li>$[1, 1, 2, 1, 2, 3, 1, 2, 3, 4, \color{red}{1, 2, 3}, 4, 5]$. </li></ul><p>In the third test case, the blackboard contains the numbers</p><p>$$b = [1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]$$</p><p>and James's list of favorite numbers is$[3, 1, 2, 3, 4, 1]$. There is only$1$subarray of$b$equal to$[3, 1, 2, 3, 4, 1]$(highlighted in red):</p><ul> <li>$[1, 1, 2, 1, 2, \color{red}{3, 1, 2, 3, 4, 1}, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]$. ## Samples ```input1 5 4 1 1 5 3 1 2 3 6 6 3 1 2 3 4 1 100000 1 100000 4 2 1 1 ``` ```output1 4 3 1 1 1 ```$$

在线编程 IDE

建议全屏模式获得最佳体验