#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 7;
const int Q = 1e2 + 7;
int n, l;
int a[N];
bitset<N> b[N];
int dist[2][N];
int sum[N];
int ans[Q][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
b[i][j] = (a[i] != a[j]);
}
}
vector<pair<int, int>> queries;
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int k;
cin >> k;
queries.push_back({k, i});
}
for (int i = 1; i <= n - l + 1; ++i) {
memset(sum, 0, sizeof(sum));
memset(dist[i & 1], 0, sizeof(dist[i & 1]));
if (i == 1) {
for (int j = 1; j <= n - l + 1; ++j) {
for (int k = 0; k < l; ++k) {
dist[i & 1][j] += b[i + k][j + k];
}
sum[dist[i & 1][j]]++;
}
} else {
dist[i & 1][1] = 0;
for (int j = 0; j < l; ++j) {
dist[i & 1][1] += b[i + j][1 + j];
}
sum[dist[i & 1][1]]++;
for (int j = 2; j <= n - l + 1; ++j) {
dist[i & 1][j] = dist[(i & 1) ^ 1][j - 1] - b[i - 1][j - 1] + b[i + l - 1][j + l - 1];
sum[dist[i & 1][j]]++;
}
}
for (int j = 1; j <= l; ++j) {
sum[j] += sum[j - 1];
}
for (auto it : queries) {
ans[it.second][i] = sum[it.first];
}
}
for (int i = 1; i <= q; ++i) {
for (int j = 1; j <= n - l + 1; ++j) {
cout << ans[i][j] - 1 << " ";
}
cout << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
22 ms |
7004 KB |
Output is correct |
14 |
Correct |
19 ms |
7256 KB |
Output is correct |
15 |
Correct |
19 ms |
7076 KB |
Output is correct |
16 |
Correct |
21 ms |
7256 KB |
Output is correct |
17 |
Correct |
21 ms |
7112 KB |
Output is correct |
18 |
Correct |
21 ms |
7004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
15072 KB |
Output is correct |
2 |
Correct |
544 ms |
14932 KB |
Output is correct |
3 |
Correct |
394 ms |
14868 KB |
Output is correct |
4 |
Correct |
416 ms |
15320 KB |
Output is correct |
5 |
Correct |
363 ms |
14936 KB |
Output is correct |
6 |
Correct |
418 ms |
15048 KB |
Output is correct |
7 |
Correct |
366 ms |
14928 KB |
Output is correct |
8 |
Correct |
405 ms |
15080 KB |
Output is correct |
9 |
Correct |
419 ms |
14836 KB |
Output is correct |
10 |
Correct |
412 ms |
15000 KB |
Output is correct |
11 |
Correct |
36 ms |
6260 KB |
Output is correct |
12 |
Correct |
314 ms |
13732 KB |
Output is correct |
13 |
Correct |
373 ms |
14828 KB |
Output is correct |
14 |
Correct |
391 ms |
14928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
549 ms |
15072 KB |
Output is correct |
2 |
Correct |
544 ms |
14932 KB |
Output is correct |
3 |
Correct |
394 ms |
14868 KB |
Output is correct |
4 |
Correct |
416 ms |
15320 KB |
Output is correct |
5 |
Correct |
363 ms |
14936 KB |
Output is correct |
6 |
Correct |
418 ms |
15048 KB |
Output is correct |
7 |
Correct |
366 ms |
14928 KB |
Output is correct |
8 |
Correct |
405 ms |
15080 KB |
Output is correct |
9 |
Correct |
419 ms |
14836 KB |
Output is correct |
10 |
Correct |
412 ms |
15000 KB |
Output is correct |
11 |
Correct |
36 ms |
6260 KB |
Output is correct |
12 |
Correct |
314 ms |
13732 KB |
Output is correct |
13 |
Correct |
373 ms |
14828 KB |
Output is correct |
14 |
Correct |
391 ms |
14928 KB |
Output is correct |
15 |
Correct |
379 ms |
14772 KB |
Output is correct |
16 |
Correct |
424 ms |
15004 KB |
Output is correct |
17 |
Correct |
426 ms |
14888 KB |
Output is correct |
18 |
Correct |
416 ms |
15208 KB |
Output is correct |
19 |
Correct |
424 ms |
14872 KB |
Output is correct |
20 |
Correct |
417 ms |
15004 KB |
Output is correct |
21 |
Correct |
414 ms |
15000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4700 KB |
Output is correct |
3 |
Correct |
1 ms |
4700 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4700 KB |
Output is correct |
6 |
Correct |
1 ms |
4700 KB |
Output is correct |
7 |
Correct |
1 ms |
4700 KB |
Output is correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Correct |
2 ms |
4956 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
4956 KB |
Output is correct |
12 |
Correct |
2 ms |
4956 KB |
Output is correct |
13 |
Correct |
22 ms |
7004 KB |
Output is correct |
14 |
Correct |
19 ms |
7256 KB |
Output is correct |
15 |
Correct |
19 ms |
7076 KB |
Output is correct |
16 |
Correct |
21 ms |
7256 KB |
Output is correct |
17 |
Correct |
21 ms |
7112 KB |
Output is correct |
18 |
Correct |
21 ms |
7004 KB |
Output is correct |
19 |
Correct |
549 ms |
15072 KB |
Output is correct |
20 |
Correct |
544 ms |
14932 KB |
Output is correct |
21 |
Correct |
394 ms |
14868 KB |
Output is correct |
22 |
Correct |
416 ms |
15320 KB |
Output is correct |
23 |
Correct |
363 ms |
14936 KB |
Output is correct |
24 |
Correct |
418 ms |
15048 KB |
Output is correct |
25 |
Correct |
366 ms |
14928 KB |
Output is correct |
26 |
Correct |
405 ms |
15080 KB |
Output is correct |
27 |
Correct |
419 ms |
14836 KB |
Output is correct |
28 |
Correct |
412 ms |
15000 KB |
Output is correct |
29 |
Correct |
36 ms |
6260 KB |
Output is correct |
30 |
Correct |
314 ms |
13732 KB |
Output is correct |
31 |
Correct |
373 ms |
14828 KB |
Output is correct |
32 |
Correct |
391 ms |
14928 KB |
Output is correct |
33 |
Correct |
379 ms |
14772 KB |
Output is correct |
34 |
Correct |
424 ms |
15004 KB |
Output is correct |
35 |
Correct |
426 ms |
14888 KB |
Output is correct |
36 |
Correct |
416 ms |
15208 KB |
Output is correct |
37 |
Correct |
424 ms |
14872 KB |
Output is correct |
38 |
Correct |
417 ms |
15004 KB |
Output is correct |
39 |
Correct |
414 ms |
15000 KB |
Output is correct |
40 |
Correct |
551 ms |
17724 KB |
Output is correct |
41 |
Correct |
286 ms |
17256 KB |
Output is correct |
42 |
Correct |
400 ms |
17744 KB |
Output is correct |
43 |
Correct |
425 ms |
17392 KB |
Output is correct |
44 |
Correct |
426 ms |
17796 KB |
Output is correct |
45 |
Correct |
590 ms |
20760 KB |
Output is correct |
46 |
Correct |
264 ms |
17492 KB |
Output is correct |
47 |
Correct |
452 ms |
20916 KB |
Output is correct |
48 |
Correct |
459 ms |
19056 KB |
Output is correct |
49 |
Correct |
466 ms |
19684 KB |
Output is correct |