#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 10, MAXQ = 110;
int n, len, q;
int arr[MAXN], pos[MAXN];
int ans[MAXN][MAXQ];
int bit[MAXN][MAXQ];
vector< pair<int, int> > qry;
int
main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> len;
for (int i = 1; i <= n; i++)
cin >> arr[i];
cin >> q;
for (int i = 1, k; i <= q; i++)
cin >> k, qry.emplace_back(k, i);
sort(begin(qry), end(qry));
memset(pos, 0xff, MAXN * sizeof(int));
pos[len + 1] = q;
for (int i = q - 1; i >= 0; i--) pos[qry[i].first] = i;
for (int i = len; i >= 0; i--) pos[i] = pos[i] == -1 ? pos[i + 1] : pos[i];
for (int d = 1; d <= n - len; d++) {
int dist = -1;
for (int i = 1; i + d + len - 1 <= n; i++) {
if (dist == -1) {
dist = 0;
for (int k = 0; k < len; k++)
dist += arr[i + k] != arr[i + d + k];
} else dist += arr[i + len - 1] != arr[i + len - 1 + d];
int j = pos[dist];
bit[i][j]++;
bit[i + d][j]++;
dist -= arr[i] != arr[i + d];
}
}
for (int i = 1; i <= n - len + 1; i++)
for (int j = 0, acc = 0; j < q; j++)
acc += bit[i][j], ans[i][qry[j].second] = acc;
for (int i = 1; i <= q; i++) {
for (int j = 1; j + len - 1 <= n; j++)
cout << ans[j][i] << " ";
cout << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
18 ms |
2140 KB |
Output is correct |
14 |
Correct |
10 ms |
1620 KB |
Output is correct |
15 |
Correct |
9 ms |
1488 KB |
Output is correct |
16 |
Correct |
17 ms |
1996 KB |
Output is correct |
17 |
Correct |
14 ms |
1888 KB |
Output is correct |
18 |
Correct |
15 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
420 ms |
9068 KB |
Output is correct |
2 |
Correct |
423 ms |
8940 KB |
Output is correct |
3 |
Correct |
417 ms |
8956 KB |
Output is correct |
4 |
Correct |
395 ms |
9036 KB |
Output is correct |
5 |
Correct |
120 ms |
4812 KB |
Output is correct |
6 |
Correct |
371 ms |
8476 KB |
Output is correct |
7 |
Correct |
122 ms |
4824 KB |
Output is correct |
8 |
Correct |
217 ms |
6444 KB |
Output is correct |
9 |
Correct |
383 ms |
8780 KB |
Output is correct |
10 |
Correct |
393 ms |
8928 KB |
Output is correct |
11 |
Correct |
18 ms |
2004 KB |
Output is correct |
12 |
Correct |
202 ms |
6416 KB |
Output is correct |
13 |
Correct |
161 ms |
5588 KB |
Output is correct |
14 |
Correct |
166 ms |
5480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
420 ms |
9068 KB |
Output is correct |
2 |
Correct |
423 ms |
8940 KB |
Output is correct |
3 |
Correct |
417 ms |
8956 KB |
Output is correct |
4 |
Correct |
395 ms |
9036 KB |
Output is correct |
5 |
Correct |
120 ms |
4812 KB |
Output is correct |
6 |
Correct |
371 ms |
8476 KB |
Output is correct |
7 |
Correct |
122 ms |
4824 KB |
Output is correct |
8 |
Correct |
217 ms |
6444 KB |
Output is correct |
9 |
Correct |
383 ms |
8780 KB |
Output is correct |
10 |
Correct |
393 ms |
8928 KB |
Output is correct |
11 |
Correct |
18 ms |
2004 KB |
Output is correct |
12 |
Correct |
202 ms |
6416 KB |
Output is correct |
13 |
Correct |
161 ms |
5588 KB |
Output is correct |
14 |
Correct |
166 ms |
5480 KB |
Output is correct |
15 |
Correct |
402 ms |
8668 KB |
Output is correct |
16 |
Correct |
338 ms |
8200 KB |
Output is correct |
17 |
Correct |
417 ms |
9008 KB |
Output is correct |
18 |
Correct |
405 ms |
8964 KB |
Output is correct |
19 |
Correct |
403 ms |
8968 KB |
Output is correct |
20 |
Correct |
408 ms |
8976 KB |
Output is correct |
21 |
Correct |
403 ms |
8976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
584 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
18 ms |
2140 KB |
Output is correct |
14 |
Correct |
10 ms |
1620 KB |
Output is correct |
15 |
Correct |
9 ms |
1488 KB |
Output is correct |
16 |
Correct |
17 ms |
1996 KB |
Output is correct |
17 |
Correct |
14 ms |
1888 KB |
Output is correct |
18 |
Correct |
15 ms |
1872 KB |
Output is correct |
19 |
Correct |
420 ms |
9068 KB |
Output is correct |
20 |
Correct |
423 ms |
8940 KB |
Output is correct |
21 |
Correct |
417 ms |
8956 KB |
Output is correct |
22 |
Correct |
395 ms |
9036 KB |
Output is correct |
23 |
Correct |
120 ms |
4812 KB |
Output is correct |
24 |
Correct |
371 ms |
8476 KB |
Output is correct |
25 |
Correct |
122 ms |
4824 KB |
Output is correct |
26 |
Correct |
217 ms |
6444 KB |
Output is correct |
27 |
Correct |
383 ms |
8780 KB |
Output is correct |
28 |
Correct |
393 ms |
8928 KB |
Output is correct |
29 |
Correct |
18 ms |
2004 KB |
Output is correct |
30 |
Correct |
202 ms |
6416 KB |
Output is correct |
31 |
Correct |
161 ms |
5588 KB |
Output is correct |
32 |
Correct |
166 ms |
5480 KB |
Output is correct |
33 |
Correct |
402 ms |
8668 KB |
Output is correct |
34 |
Correct |
338 ms |
8200 KB |
Output is correct |
35 |
Correct |
417 ms |
9008 KB |
Output is correct |
36 |
Correct |
405 ms |
8964 KB |
Output is correct |
37 |
Correct |
403 ms |
8968 KB |
Output is correct |
38 |
Correct |
408 ms |
8976 KB |
Output is correct |
39 |
Correct |
403 ms |
8976 KB |
Output is correct |
40 |
Correct |
434 ms |
9656 KB |
Output is correct |
41 |
Correct |
13 ms |
1364 KB |
Output is correct |
42 |
Correct |
419 ms |
9668 KB |
Output is correct |
43 |
Correct |
388 ms |
9092 KB |
Output is correct |
44 |
Correct |
394 ms |
9216 KB |
Output is correct |
45 |
Correct |
498 ms |
12788 KB |
Output is correct |
46 |
Correct |
19 ms |
1584 KB |
Output is correct |
47 |
Correct |
481 ms |
12864 KB |
Output is correct |
48 |
Correct |
443 ms |
10748 KB |
Output is correct |
49 |
Correct |
453 ms |
11444 KB |
Output is correct |