This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, l; cin >> n >> l;
int a[n + 1];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int q; cin >> q;
int k[q], k2[q];
for (int i = 0; i < q; i++) {
cin >> k[i]; k2[i] = k[i];
}
sort(k2, k2 + q);
int prf[n + 1];
prf[0] = 0;
int res[n + 1][q + 1];
memset(res, 0, sizeof(res));
for (int j = 1; j < n; j++) {
for (int i = 1; i <= n - j; i++) {
prf[i] = prf[i - 1] + (a[i] != a[i + j]);
}
for (int i = 1; i + j + l - 1 <= n; i++) {
int p = lower_bound(k2, k2 + q, prf[i + l - 1] - prf[i - 1]) - k2;
res[i][p]++;
res[i + j][p]++;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < q; j++) {
res[i][j] += res[i][j - 1];
}
}
for (int i = 0; i < q; i++) {
for (int j = 1; j <= n - l + 1; j++) {
cout << res[j][lower_bound(k2, k2 + q, k[i]) - k2] << " ";
}
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... |