#include <bits/stdc++.h>
#define maxn 10005
using namespace std;
int n, l;
int a[maxn];
int rtGames[maxn];
int kq[105][maxn];
int queries[maxn], q, ans[maxn];
int s[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> l;
for (int i = 1; i <= n; i++) cin >> a[i];
cin >> q;
for (int i = 1; i <= q; i++) cin >> queries[i];
for (int i = 0; i < l; i++)
for (int j = 2; j <= n-l+1; j++)
rtGames[j] += (a[1+i] == a[j+i]);
for (int i = 1; i <= q; i++)
for (int j = 2; j <= n-l+1; j++) kq[i][1] += (l-rtGames[j] <= queries[i]);
for (int i = 1; i <= n; i++) ans[i] = rtGames[i];
for (int i = 2; i <= n-l+1; i++) {
int cr = ans[i];
for (int j = n-l+1; j >= 2; j--) ans[j] = ans[j-1];
ans[i-1] = cr;
ans[1] = rtGames[i];
for (int j = 2; j <= n-l+1; j++) {
if (j == i || j == i-1) continue;
ans[j] -= (a[i-1] == a[j-1]);
ans[j] += (a[i+l-1] == a[j+l-1]);
}
for (int j = 0; j <= l; j++) s[j] = 0;
for (int j = 1; j <= n-l+1; j++)
if (i != j) ++s[l-ans[j]];
for (int j = 1; j <= l; j++) s[j] += s[j-1];
for (int j = 1; j <= q; j++) kq[j][i] += s[queries[j]];
}
for (int i = 1; i <= q; i++) {
for (int j = 1; j <= n-l+1; j++) cout << kq[i][j] << ' ';
cout << "\n";
}
}
/*
6 2
1 2 1 3 2 1
2
1
2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |