-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1955D.cpp
More file actions
76 lines (61 loc) · 1.5 KB
/
1955D.cpp
File metadata and controls
76 lines (61 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define MAXN 2000000000
#define llu unsigned long long
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef DEBUG
freopen("in.in", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) {
int ans = 0;
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n, 0);
vector<int> b(m, 0);
unordered_map<int, int> um_a;
unordered_map<int, int> um_b;
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < m; ++i)
cin >> b[i];
for (auto &v : b)
um_b[v]++;
um_a.clear();
int valid = 0;
for (int start = 0; start + m- 1 < n; ++start) {
if (start == 0) {
for (int j = 0; j < m; ++j) {
um_a[a[start + j]]++;
}
for (auto &bp : um_b) {
valid += min(um_a[bp.first], bp.second);
}
} else {
int left = a[start-1];
int right = a[start+m-1];
valid -= min(um_a[left], um_b[left]);
valid -= min(um_a[right], um_b[right]);
// remove left boundary
um_a[left]--;
// add right boundary
um_a[right]++;
valid += min(um_a[left], um_b[left]);
valid += min(um_a[right], um_b[right]);
}
if (valid >= k)
ans++;
}
cout << ans << endl;
}
return 0;
}