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(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, l;
cin >> n >> l;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int q;
cin >> q;
vector<pair<int, int>> qs(q);
for (int i = 0; i < q; ++i) {
cin >> qs[i].first;
qs[i].second = i;
}
sort(qs.begin(), qs.end());
vector<int> nx(l + 1);
int p = 0;
for (int i = 0; i <= l; ++i) {
while (p < q && qs[p].first < i) {
p++;
}
nx[i] = p;
}
vector<vector<int>> ans(q, vector<int>(n - l + 1));
auto inc = [&](int x, int y, int mis) {
if (nx[mis] < q) {
ans[nx[mis]][x]++;
ans[nx[mis]][y]++;
}
};
for (int shift = 1; shift <= n - l; ++shift) {
int mis = 0;
for (int i = 0; i < l; ++i) {
if (a[i] != a[shift + i]) {
mis++;
}
}
inc(0, shift, mis);
for (int i = 1; i + shift + l <= n; ++i) {
if (a[i - 1] != a[i + shift - 1]) {
mis--;
}
if (a[i + l - 1] != a[i + shift + l - 1]) {
mis++;
}
inc(i, i + shift, mis);
}
}
for (int j = 1; j < q; ++j) {
for (int i = 0; i <= n - l; ++i) {
ans[j][i] += ans[j - 1][i];
}
}
vector<vector<int>> out(q);
for (int i = 0; i < q; ++i) {
out[qs[i].second] = ans[i];
}
for (int i = 0; i < q; ++i) {
for (int j = 0; j <= n - l; ++j) {
cout << out[i][j] << ' ';
}
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... |