#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef pair <ll, ll> pii;
const int N = 10007, Q = 107, inf = 1e9;
int n, l, q;
int a[N], k[Q], ps[N][Q], gt[N], wh[N];
vector <int> v;
int main () {
FIO;
cin >> n >> l;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> q;
for (int i = 0; i < q; i++) {
cin >> k[i];
v.pb(k[i]);
}
sort(all(v)); v.erase(unique(all(v)), v.end());
for (int i = 0; i < v.size(); i++) wh[v[i]] = i;
for (int i = 0; i <= l; i++) gt[i] = inf;
for (int i = 0; i < v.size(); i++) gt[v[i]] = i;
for (int i = l-1; i >= 0; i--) gt[i] = min(gt[i], gt[i+1]);
for (int i = 1; i+l-1 < n; i++) {
int cur = 0;
for (int j = 0; j < l; j++) cur += (a[j] != a[j+i]);
if (gt[cur] != inf) {
ps[0][gt[cur]]++;
ps[i][gt[cur]]++;
}
for (int j = 1; j+i+l-1 < n; j++) {
cur -= (a[j-1] != a[j+i-1]);
cur += (a[j+l-1] != a[j+l+i-1]);
if (gt[cur] != inf) {
ps[j][gt[cur]]++;
ps[j+i][gt[cur]]++;
}
}
}
for (int i = 0; i < n-l+1; i++) {
for (int j = 1; j < q; j++) ps[i][j] += ps[i][j-1];
}
for (int i = 0; i < q; i++) {
for (int j = 0; j < n-l+1; j++) cout << ps[j][wh[k[i]]] << " ";
cout << "\n";
}
return 0;
}
# | 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... |