#include "bits/stdc++.h"
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, l;
cin >> n >> l;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int q;
cin >> q;
vector<pair<int, int>> qs(q);
for (int i = 0; i < q; ++i) {
cin >> qs[i].first;
qs[i].second = i;
}
sort(qs.begin(), qs.end());
vector<int> nx(l + 1);
int p = 0;
for (int i = 0; i <= l; ++i) {
while (p < q && qs[p].first < i) {
p++;
}
nx[i] = p;
}
vector<vector<int>> ans(q, vector<int>(n - l + 1));
auto inc = [&](int x, int y, int mis) {
if (nx[mis] < q) {
ans[nx[mis]][x]++;
ans[nx[mis]][y]++;
}
};
for (int shift = 1; shift <= n - l; ++shift) {
int mis = 0;
for (int i = 0; i < l; ++i) {
if (a[i] != a[shift + i]) {
mis++;
}
}
inc(0, shift, mis);
for (int i = 1; i + shift + l <= n; ++i) {
if (a[i - 1] != a[i + shift - 1]) {
mis--;
}
if (a[i + l - 1] != a[i + shift + l - 1]) {
mis++;
}
inc(i, i + shift, mis);
}
}
for (int j = 1; j < q; ++j) {
for (int i = 0; i <= n - l; ++i) {
ans[j][i] += ans[j - 1][i];
}
}
vector<vector<int>> out(q);
for (int i = 0; i < q; ++i) {
out[qs[i].second] = ans[i];
}
for (int i = 0; i < q; ++i) {
for (int j = 0; j <= n - l; ++j) {
cout << out[i][j] << ' ';
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
828 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
828 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
344 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
544 KB |
Output is correct |
2 |
Correct |
483 ms |
592 KB |
Output is correct |
3 |
Correct |
126 ms |
592 KB |
Output is correct |
4 |
Correct |
79 ms |
600 KB |
Output is correct |
5 |
Correct |
42 ms |
624 KB |
Output is correct |
6 |
Correct |
72 ms |
652 KB |
Output is correct |
7 |
Correct |
67 ms |
604 KB |
Output is correct |
8 |
Correct |
96 ms |
600 KB |
Output is correct |
9 |
Correct |
79 ms |
600 KB |
Output is correct |
10 |
Correct |
77 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
55 ms |
636 KB |
Output is correct |
13 |
Correct |
52 ms |
600 KB |
Output is correct |
14 |
Correct |
56 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
544 KB |
Output is correct |
2 |
Correct |
483 ms |
592 KB |
Output is correct |
3 |
Correct |
126 ms |
592 KB |
Output is correct |
4 |
Correct |
79 ms |
600 KB |
Output is correct |
5 |
Correct |
42 ms |
624 KB |
Output is correct |
6 |
Correct |
72 ms |
652 KB |
Output is correct |
7 |
Correct |
67 ms |
604 KB |
Output is correct |
8 |
Correct |
96 ms |
600 KB |
Output is correct |
9 |
Correct |
79 ms |
600 KB |
Output is correct |
10 |
Correct |
77 ms |
640 KB |
Output is correct |
11 |
Correct |
8 ms |
344 KB |
Output is correct |
12 |
Correct |
55 ms |
636 KB |
Output is correct |
13 |
Correct |
52 ms |
600 KB |
Output is correct |
14 |
Correct |
56 ms |
636 KB |
Output is correct |
15 |
Correct |
197 ms |
592 KB |
Output is correct |
16 |
Correct |
72 ms |
600 KB |
Output is correct |
17 |
Correct |
101 ms |
652 KB |
Output is correct |
18 |
Correct |
76 ms |
648 KB |
Output is correct |
19 |
Correct |
80 ms |
600 KB |
Output is correct |
20 |
Correct |
76 ms |
644 KB |
Output is correct |
21 |
Correct |
84 ms |
652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
756 KB |
Output is correct |
5 |
Correct |
1 ms |
828 KB |
Output is correct |
6 |
Correct |
1 ms |
452 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
10 ms |
344 KB |
Output is correct |
14 |
Correct |
5 ms |
600 KB |
Output is correct |
15 |
Correct |
4 ms |
600 KB |
Output is correct |
16 |
Correct |
5 ms |
856 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
5 ms |
600 KB |
Output is correct |
19 |
Correct |
337 ms |
544 KB |
Output is correct |
20 |
Correct |
483 ms |
592 KB |
Output is correct |
21 |
Correct |
126 ms |
592 KB |
Output is correct |
22 |
Correct |
79 ms |
600 KB |
Output is correct |
23 |
Correct |
42 ms |
624 KB |
Output is correct |
24 |
Correct |
72 ms |
652 KB |
Output is correct |
25 |
Correct |
67 ms |
604 KB |
Output is correct |
26 |
Correct |
96 ms |
600 KB |
Output is correct |
27 |
Correct |
79 ms |
600 KB |
Output is correct |
28 |
Correct |
77 ms |
640 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
55 ms |
636 KB |
Output is correct |
31 |
Correct |
52 ms |
600 KB |
Output is correct |
32 |
Correct |
56 ms |
636 KB |
Output is correct |
33 |
Correct |
197 ms |
592 KB |
Output is correct |
34 |
Correct |
72 ms |
600 KB |
Output is correct |
35 |
Correct |
101 ms |
652 KB |
Output is correct |
36 |
Correct |
76 ms |
648 KB |
Output is correct |
37 |
Correct |
80 ms |
600 KB |
Output is correct |
38 |
Correct |
76 ms |
644 KB |
Output is correct |
39 |
Correct |
84 ms |
652 KB |
Output is correct |
40 |
Correct |
532 ms |
2900 KB |
Output is correct |
41 |
Correct |
9 ms |
600 KB |
Output is correct |
42 |
Correct |
111 ms |
2868 KB |
Output is correct |
43 |
Correct |
85 ms |
2396 KB |
Output is correct |
44 |
Correct |
85 ms |
2384 KB |
Output is correct |
45 |
Correct |
578 ms |
11932 KB |
Output is correct |
46 |
Correct |
15 ms |
1624 KB |
Output is correct |
47 |
Correct |
212 ms |
12112 KB |
Output is correct |
48 |
Correct |
124 ms |
10064 KB |
Output is correct |
49 |
Correct |
125 ms |
10832 KB |
Output is correct |