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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
typedef long long ll;
using namespace std;
const int maxn = 1e4 + 5, maxq = 105;
int n, l, q;
int a[maxn];
int d[2][maxn];
int sum[maxn];
int queries[maxq];
int ans[maxq][maxn];
int dif(int i, int j)
{
int cnt = 0;
for (int k = 0; k < l; k++) cnt += (a[i + k] != a[j + k]);
return cnt;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> q;
for (int i = 0; i < q; i++) cin >> queries[i];
for (int i = 0; i + l - 1 < n; i++) d[0][i] = dif(0, i);
for (int i = 0; i < n; i++)
{
fill(sum, sum + n, 0);
int nw = i&1, pv = nw^1;
if (i)
{
d[nw][0] = dif(i, 0);
for (int j = 1; j + l - 1 < n; j++)
d[nw][j] = d[pv][j-1] - (a[i-1] != a[j-1]) + (a[i+l-1] != a[j+l-1]);
}
for (int j = 0; j + l - 1 < n; j++) sum[d[nw][j]]++;
for (int j = 1; j <= n; j++) sum[j] += sum[j-1];
for (int j = 0; j < q; j++) ans[j][i] = sum[queries[j]] - 1;
}
for (int i = 0; i < q; i++) for (int j = 0; j + l - 1 < n; j++)
cout << ans[i][j] << " \n"[j + l - 1 == n - 1];
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... |