【形式化解释】
第一行输入整数
——测试用例组数。
每个测试用例:
一行三个整数
;
一行
个整数
;
一行
个整数
。
输入保证所有测试用例的之和、
之和均不超过
。
对每个测试用例输出一行整数,表示满足条件的子段数量。
1 4 1 1 4 1 5 6 6
1
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const t = Number(await readline());
for (let l = 0; l < t; l++) {
const [n, m, k] = (await readline()).split(" ").map(Number);
const listA = (await readline()).split(" ").map(Number);
const listB = (await readline()).split(" ").map(Number);
let map = new Map();
for (let c of listB) {
map.set(c, (map.get(c) || 0) + 1);
}
let i = 0;
let j = 0;
let cnt = 0;
let countMap = new Map();
while (j < m) {
countMap.set(listA[j], (countMap.get(listA[j]) || 0) + 1);
if (
map.has(listA[j]) &&
countMap.get(listA[j]) <= map.get(listA[j]) &&
j < m
) {
cnt++;
}
j++;
}
j--;
let ans = 0;
if (cnt >= k) {
ans++;
// console.log('0 ans', ans);
}
// console.log('initial i, j ', i, j);
while (j < n) {
i++;
j++;
const removedChar = listA[i - 1];
countMap.set(removedChar, countMap.get(removedChar) - 1);
if (
map.has(removedChar) &&
countMap.get(removedChar) + 1 <= map.get(removedChar)
) {
cnt--;
}
const addedChar = listA[j];
countMap.set(addedChar, (countMap.get(addedChar) || 0) + 1);
if (
map.has(addedChar) &&
countMap.get(addedChar) - 1 < map.get(addedChar)
) {
cnt++;
}
// console.log("i,j", i, j, new Map(countMap));
if (cnt >= k && j < n) {
ans++;
// console.log("cnt, ans", cnt, ans);
// console.log("i,j ", i, j);
}
}
console.log(ans);
}
})();