이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N, L, q, A[10005];
int ans[100][10005];
int true_ans[100][10005];
pair<int, int> Q[100];
int pos[100];
int main() {
ios_base::sync_with_stdio(0);
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 >> Q[i].first;
for (int i = 0; i < q; i++) Q[i].second = i;
sort(Q, Q + q);
for (int i = 0; i < q; i++) pos[Q[i].second] = i;
/* The segment compared is segment i...(i + L - 1) and (i + shift)...(i + L + shift - 1) */
for (int shift = 1, similiar = 0; shift + L - 1 < N; shift++, similiar = 0) {
for (int i = 0; i < L; i++)
if (A[i] == A[i + shift]) similiar++;
for (int i = 0; i + shift + L - 1 < N; i++) { // then sliding window can be used
int j = lower_bound(Q, Q + q, make_pair(L - similiar, -1)) - Q;
ans[j][i]++, ans[j][i + shift]++; // Add 1 to the answer for the lowest Q possible
if (A[i] == A[i + shift]) similiar--;
if (A[i + L] == A[i + shift + L]) similiar++;
}
}
/* If Q[i] <= Q[j], then all answers from Q[i] can be used in Q[j] */
for (int i = 0; i < N; i++)
for (int j = 1; j < q; j++)
ans[j][i] += ans[j - 1][i];
for (int i = 0; i < q; i++) {
for (int j = 0; j < N - L + 1; j++)
cout << ans[pos[i]][j] << " ";
cout << "\n";
}
}
# | 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... |