#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[l] = p;
}
vector<vector<int>> ans(q, vector<int>(n));
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 i = 0; i < n; ++i) {
for (int j = 1; j < q; ++j) {
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 + 1; ++j) {
cout << out[i][j] << ' ';
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
365 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
365 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |