#include <bits/stdc++.h>
using ll = long long;
template <class T>
using Vec = std::vector<T>;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, L;
std::cin >> N >> L;
Vec<int> A(N);
for (auto& x: A) {
std::cin >> x;
}
int Q;
std::cin >> Q;
Vec<int> K(Q);
for (auto& x: K) {
std::cin >> x;
}
auto cmp = K;
std::sort(cmp.begin(), cmp.end());
cmp.erase(std::unique(cmp.begin(), cmp.end()), cmp.end());
const int M = (int) cmp.size();
Vec<int> lowb(L + 1, M);
for (int i = 0; i < M; ++i) {
lowb[cmp[i]] = i;
}
for (int i = L - 1; i >= 0; --i) {
lowb[i] = std::min(lowb[i], lowb[i + 1]);
}
Vec<Vec<int>> count(N - L + 1, Vec<int>(M));
for (int k = 1; k <= N - L; ++k) {
Vec<int> sum(N - L + 1);
const auto add = [&](const int l, const int r) {
sum[l] += 1;
if (r < N - L) {
sum[r + 1] -= 1;
}
};
for (int i = 0; i < N - k; ++i) {
if (A[i] != A[i + k]) {
add(std::max(0, i - L + 1), std::min(i, N - L - k));
}
}
for (int i = 0; i < N - L; ++i) {
sum[i + 1] += sum[i];
}
for (int i = 0; i <= N - L - k; ++i) {
const auto k = lowb[sum[i]];
if (k < M) {
count[i][k] += 1;
}
}
}
for (int k = 1; k <= N - L; ++k) {
Vec<int> sum(N - L + 1);
const auto add = [&](const int l, const int r) {
sum[l] += 1;
if (r < N - L) {
sum[r + 1] -= 1;
}
};
for (int i = k; i < N; ++i) {
if (A[i] != A[i - k]) {
add(std::max(k, i - L + 1), std::min(i, N - L));
}
}
for (int i = 0; i < N - L; ++i) {
sum[i + 1] += sum[i];
}
for (int i = k; i <= N - L; ++i) {
const auto k = lowb[sum[i]];
if (k < M) {
count[i][k] += 1;
}
}
}
for (int i = 0; i <= N - L; ++i) {
for (int k = 1; k < M; ++k) {
count[i][k] += count[i][k - 1];
}
}
for (const auto x: K) {
const auto k = lowb[x];
for (int i = 0; i <= N - L; ++i) {
std::cout << count[i][k] << " \n"[i == N - L];
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
48 ms |
428 KB |
Output is correct |
14 |
Correct |
28 ms |
504 KB |
Output is correct |
15 |
Correct |
17 ms |
476 KB |
Output is correct |
16 |
Correct |
24 ms |
564 KB |
Output is correct |
17 |
Correct |
26 ms |
580 KB |
Output is correct |
18 |
Correct |
22 ms |
544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1200 ms |
972 KB |
Output is correct |
2 |
Correct |
1016 ms |
972 KB |
Output is correct |
3 |
Correct |
647 ms |
972 KB |
Output is correct |
4 |
Correct |
528 ms |
1092 KB |
Output is correct |
5 |
Correct |
231 ms |
744 KB |
Output is correct |
6 |
Correct |
509 ms |
1000 KB |
Output is correct |
7 |
Correct |
314 ms |
836 KB |
Output is correct |
8 |
Correct |
548 ms |
844 KB |
Output is correct |
9 |
Correct |
551 ms |
1024 KB |
Output is correct |
10 |
Correct |
541 ms |
960 KB |
Output is correct |
11 |
Correct |
37 ms |
460 KB |
Output is correct |
12 |
Correct |
358 ms |
844 KB |
Output is correct |
13 |
Correct |
321 ms |
836 KB |
Output is correct |
14 |
Correct |
319 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1200 ms |
972 KB |
Output is correct |
2 |
Correct |
1016 ms |
972 KB |
Output is correct |
3 |
Correct |
647 ms |
972 KB |
Output is correct |
4 |
Correct |
528 ms |
1092 KB |
Output is correct |
5 |
Correct |
231 ms |
744 KB |
Output is correct |
6 |
Correct |
509 ms |
1000 KB |
Output is correct |
7 |
Correct |
314 ms |
836 KB |
Output is correct |
8 |
Correct |
548 ms |
844 KB |
Output is correct |
9 |
Correct |
551 ms |
1024 KB |
Output is correct |
10 |
Correct |
541 ms |
960 KB |
Output is correct |
11 |
Correct |
37 ms |
460 KB |
Output is correct |
12 |
Correct |
358 ms |
844 KB |
Output is correct |
13 |
Correct |
321 ms |
836 KB |
Output is correct |
14 |
Correct |
319 ms |
836 KB |
Output is correct |
15 |
Correct |
903 ms |
940 KB |
Output is correct |
16 |
Correct |
489 ms |
976 KB |
Output is correct |
17 |
Correct |
580 ms |
1036 KB |
Output is correct |
18 |
Correct |
542 ms |
1032 KB |
Output is correct |
19 |
Correct |
546 ms |
1036 KB |
Output is correct |
20 |
Correct |
541 ms |
1092 KB |
Output is correct |
21 |
Correct |
536 ms |
1036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
316 KB |
Output is correct |
13 |
Correct |
48 ms |
428 KB |
Output is correct |
14 |
Correct |
28 ms |
504 KB |
Output is correct |
15 |
Correct |
17 ms |
476 KB |
Output is correct |
16 |
Correct |
24 ms |
564 KB |
Output is correct |
17 |
Correct |
26 ms |
580 KB |
Output is correct |
18 |
Correct |
22 ms |
544 KB |
Output is correct |
19 |
Correct |
1200 ms |
972 KB |
Output is correct |
20 |
Correct |
1016 ms |
972 KB |
Output is correct |
21 |
Correct |
647 ms |
972 KB |
Output is correct |
22 |
Correct |
528 ms |
1092 KB |
Output is correct |
23 |
Correct |
231 ms |
744 KB |
Output is correct |
24 |
Correct |
509 ms |
1000 KB |
Output is correct |
25 |
Correct |
314 ms |
836 KB |
Output is correct |
26 |
Correct |
548 ms |
844 KB |
Output is correct |
27 |
Correct |
551 ms |
1024 KB |
Output is correct |
28 |
Correct |
541 ms |
960 KB |
Output is correct |
29 |
Correct |
37 ms |
460 KB |
Output is correct |
30 |
Correct |
358 ms |
844 KB |
Output is correct |
31 |
Correct |
321 ms |
836 KB |
Output is correct |
32 |
Correct |
319 ms |
836 KB |
Output is correct |
33 |
Correct |
903 ms |
940 KB |
Output is correct |
34 |
Correct |
489 ms |
976 KB |
Output is correct |
35 |
Correct |
580 ms |
1036 KB |
Output is correct |
36 |
Correct |
542 ms |
1032 KB |
Output is correct |
37 |
Correct |
546 ms |
1036 KB |
Output is correct |
38 |
Correct |
541 ms |
1092 KB |
Output is correct |
39 |
Correct |
536 ms |
1036 KB |
Output is correct |
40 |
Correct |
1533 ms |
2360 KB |
Output is correct |
41 |
Correct |
55 ms |
588 KB |
Output is correct |
42 |
Correct |
638 ms |
2348 KB |
Output is correct |
43 |
Correct |
542 ms |
2012 KB |
Output is correct |
44 |
Correct |
533 ms |
2128 KB |
Output is correct |
45 |
Correct |
1648 ms |
8512 KB |
Output is correct |
46 |
Correct |
62 ms |
1164 KB |
Output is correct |
47 |
Correct |
1184 ms |
8768 KB |
Output is correct |
48 |
Correct |
596 ms |
6332 KB |
Output is correct |
49 |
Correct |
606 ms |
6848 KB |
Output is correct |