이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1e4 + 5, Qmax = 205;
int a[Nmax], match[Nmax], where[Qmax];
pair<int,int> mat[Qmax];
int n, q, l;
int ans[Nmax][Qmax];
void new_match(int x, int y, int mat)
{
ans[x][match[mat]] ++;
ans[y][match[mat]] ++;
}
void prec(int d)
{
int i, dif = 0;
for(i=1; i<=l; ++i)
dif += (a[i] != a[d+i]);
new_match(1, d+1, dif);
for(i=l+1; i+d<=n; ++i)
{
dif += (a[i] != a[i+d]);
dif -= (a[i-l] != a[i+d-l]);
new_match(i-l+1, i+d-l+1, dif);
}
}
int main()
{
// freopen("input", "r", stdin);
cin.sync_with_stdio(false); cin.tie(0);
cin >> n >> l;
int i, j;
for(i=1; i<=n; ++i) cin >> a[i];
cin >> q;
for(i=1; i<=q; ++i) cin >> mat[i].first, mat[i].second = i;
sort(mat+1, mat+q+1);
for(i=0; i<=l; ++i)
match[i] = lower_bound(mat+1, mat+q+1, make_pair(i, 0)) - mat;
for(i=1; i<=n-l; ++i)
prec(i);
for(i=1; i<=n; ++i)
for(j=1; j<=q; ++j)
ans[i][j] += ans[i][j-1];
for(i=1; i<=q; ++i) where[mat[i].second] = i;
for(i=1; i<=q; ++i)
{
for(j=1; j<=n-l+1; ++j) cout << ans[j][where[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... |