CF1955D.Inaccurate Subsequence Search

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

Inaccurate Subsequence Search

CF1955D · Inaccurate Subsequence Search

中文题意

以下为官方英文题意(课堂讲解时请要求学生能用自己的话复述条件与目标)。

Maxim has an array aa of nn integers and an array bb of mm integers (mnm \le n). Maxim considers an array cc of length mm to be good if the elements of array cc can be rearranged in such a way that at least kk of them match the elements of array bb. For example, if b=[1,2,3,4]b = [1, 2, 3, 4] and k=3k = 3, then the arrays [4,1,2,3][4, 1, 2, 3] and [2,3,4,5][2, 3, 4, 5] are good (they can be reordered as follows: [1,2,3,4][1, 2, 3, 4] and [5,2,3,4][5, 2, 3, 4]), while the arrays [3,4,5,6][3, 4, 5, 6] and [3,4,3,4][3, 4, 3, 4] are not good. Maxim wants to choose every subsegment of array aa of length mm as the elements of array cc. Help Maxim count how many selected arrays will be good. In other words, find the number of positions 1lnm+11 \le l \le n - m + 1 such that the elements al,al+1,,al+m1a_l, a_{l+1}, \dots, a_{l + m - 1} form a good array.

Note(官方): In the first example, all subsegments are good. In the second example, good subsegments start at positions 11, 22, and 33. In the third example, good subsegments start at positions 11 and 22.

输入格式(中文)

The first line contains an integer tt (1t1041 \le t \le 10^4) — the number of test cases. The first line of each test case contains three integers nn, mm, and kk (1kmn21051 \le k \le m \le n \le 2 \cdot 10^5) — the number of elements in arrays aa and bb, the required number of matching elements. The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai1061 \le a_i \le 10^6) — the elements of array aa. Elements of the array aa are not necessarily unique. The third line of each test case contains mm integers b1,b2,,bmb_1, b_2, \dots, b_m (1bi1061 \le b_i \le 10^6) — the elements of array bb. Elements of the array bb are not necessarily unique. It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5. Similarly, it is guaranteed that the sum of mm over all test cases does not exceed 21052 \cdot 10^5.

输出格式(中文)

For each test case, output the number of good subsegments of array aa on a separate line.

样例

样例 1

输入:

5
7 4 2
4 1 2 3 4 5 6
1 2 3 4
7 4 3
4 1 2 3 4 5 6
1 2 3 4
7 4 4
4 1 2 3 4 5 6
1 2 3 4
11 5 3
9 9 2 2 10 9 7 6 3 6 3
6 9 7 8 10
4 1 1
4 1 5 6
6

输出:

4
3
2
4
1

在线编程 IDE

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