This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
template<class T> using V = vector<T>;
using vi = V<int>;
int main() {
cin.tie(0)->sync_with_stdio(0);
int N, L; cin >> N >> L;
vi A(N); for(auto& x : A) cin >> x;
int Q; cin >> Q;
vi K(Q); for(auto& x : K) cin >> x;
vi I(Q); iota(begin(I), end(I), 0); sort(begin(I), end(I), [&](int x, int y) {
return K[x] < K[y];
});
sort(begin(K), end(K));
V<vi> ans(N - L + 1, vi(Q));
vi P;
for(int d = 1; d <= N; d++) {
P = {0};
for(int i = 0; i < N - d; i++) {
P.push_back(P.back() + (A[i] != A[i + d]));
}
auto query = [&](int l, int r) {
return P[r + 1] - P[l];
};
for(int i = 0; i < N; i++) {
int j = i + d;
if (j + L - 1 >= N) continue;
int k = query(i, i + L - 1);
int ki = lower_bound(begin(K), end(K), k) - begin(K);
++ans[i][ki];
++ans[i + d][ki];
}
}
for(int i = 0; i < N - L + 1; i++) {
for(int x = 1; x < Q; x++) ans[i][x] += ans[i][x-1];
}
for(auto i : I) {
for(int x = 0; x < N - L + 1; x++) cout << ans[x][i] << " ";
cout << nl;
}
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... |