forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
87 lines (68 loc) · 2 KB
/
B.cpp
File metadata and controls
87 lines (68 loc) · 2 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
77
78
79
80
81
82
83
84
85
86
87
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << X << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define SZ(x) ((int) (x).size())
using namespace std;
#define next next__
const int MN = 200111;
int a[MN], b[MN], next[MN];
int na, nb, p;
vector<int> res;
map<int,int> need, has;
int bad, sz_need;
void add(int x, int val) {
if (has[x] == need[x]) ++bad;
has[x] += val;
if (has[x] == need[x]) --bad;
}
void solve(vector<int>& x, vector<int>& ids) {
int nx = SZ(x) - 1;
int j = 0;
bad = sz_need;
has.clear();
FOR(i,1,nx - nb + 1) {
if (i > 1) {
add(x[i-1], -1);
}
int to = i + nb - 1;
while (j < to) {
++j;
add(x[j], +1);
}
if (bad == 0) {
res.push_back(ids[i]);
}
}
}
int main() {
while (scanf("%d%d%d", &na, &nb, &p) == 3) {
FOR(i,1,na) scanf("%d", &a[i]);
FOR(i,1,nb) scanf("%d", &b[i]);
need.clear();
has.clear();
FOR(i,1,nb) need[b[i]] += 1;
sz_need = SZ(need);
res.clear();
FOR(start,1,p) {
vector<int> x;
vector<int> ids;
x.push_back(0);
ids.push_back(0); // I like numbering from 1
for(int i = start; i <= na; i += p) {
x.push_back(a[i]);
ids.push_back(i);
}
// PR(x, SZ(x)-1);
solve(x, ids);
}
sort(res.begin(), res.end());
printf("%d\n", SZ(res));
for(int x : res) printf("%d ", x); puts("");
}
}