이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int A[100001], ans[100][100001], idx[100];
int X[100001], B[100001];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int N, L; cin >> N >> L;
for (int i = 1; i <= N; ++i) cin >> A[i];
int Q; cin >> Q;
pair<int, int> qry[Q];
for (int i = 0; i < Q; ++i) {
int x; cin >> x;
qry[i] = {x, i};
}
sort(qry, qry + Q);
memset(B, -1, sizeof(B));
for (int i = 0; i < Q; ++i) {
B[qry[i].first] = i;
idx[i] = qry[i].second;
}
for (int i = L; i; --i)
if (B[i-1] == -1) B[i-1] = B[i];
for (int d = 1; d <= N - L; ++d) {
for (int i = 1; i + d <= N; ++i) {
X[i] = X[i-1] + (A[i] != A[i + d]);
}
for (int i = 1; i + d + L - 1 <= N; ++i) {
int t = B[X[i + L - 1] - X[i - 1]];
if (t == -1) continue;
++ans[t][i];
++ans[t][i + d];
}
}
for (int i = 1; i < Q; ++i)
for (int j = 1; j <= N; ++j) ans[i][j] += ans[i-1][j];
for (int i = 0; i < Q; ++i) {
for (int j = 1; j <= N - L + 1; ++j) cout << ans[idx[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... |