欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1955D.Inaccurate Subsequence Search
Inaccurate Subsequence Search
CF1955D · Inaccurate Subsequence Search
- 难度:1400
- 标签:data structures、two pointers
- 链接:https://codeforces.com/problemset/problem/1955/D
- 时间限制:2 seconds 内存限制:256 megabytes
- 出现位置:假期自习包/B-单调栈与单调队列
英文原题面
Statement
Maxim has an array of integers and an array of integers (). Maxim considers an array of length to be good if the elements of array can be rearranged in such a way that at least of them match the elements of array . For example, if and , then the arrays and are good (they can be reordered as follows: and ), while the arrays and are not good. Maxim wants to choose every subsegment of array of length as the elements of array . Help Maxim count how many selected arrays will be good. In other words, find the number of positions such that the elements form a good array.
Input
The first line contains an integer () — the number of test cases. The first line of each test case contains three integers , , and () — the number of elements in arrays and , the required number of matching elements. The second line of each test case contains integers () — the elements of array . Elements of the array are not necessarily unique. The third line of each test case contains integers () — the elements of array . Elements of the array are not necessarily unique. It is guaranteed that the sum of over all test cases does not exceed . Similarly, it is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output the number of good subsegments of array 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
样例解释(英文原文)
In the first example, all subsegments are good. In the second example, good subsegments start at positions , , and . In the third example, good subsegments start at positions and .
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |