#include <bits/stdc++.h>
using namespace std;
int N, L, q, A[10005];
int ans[100][10005];
pair<int, int> Q[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);
/* 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;
for (; j < q; j++) ans[Q[j].second][i]++, ans[Q[j].second][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[Q[j].second][i] += ans[Q[j - 1].second][i];
for (int i = 0; i < q; i++) {
for (int j = 0; j < N - L + 1; j++)
cout << ans[i][j] << " ";
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
39 ms |
632 KB |
Output is correct |
14 |
Correct |
24 ms |
504 KB |
Output is correct |
15 |
Correct |
10 ms |
504 KB |
Output is correct |
16 |
Correct |
22 ms |
740 KB |
Output is correct |
17 |
Correct |
17 ms |
660 KB |
Output is correct |
18 |
Correct |
17 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
535 ms |
468 KB |
Output is correct |
2 |
Correct |
764 ms |
464 KB |
Output is correct |
3 |
Correct |
272 ms |
504 KB |
Output is correct |
4 |
Correct |
197 ms |
376 KB |
Output is correct |
5 |
Correct |
73 ms |
504 KB |
Output is correct |
6 |
Correct |
182 ms |
532 KB |
Output is correct |
7 |
Correct |
109 ms |
376 KB |
Output is correct |
8 |
Correct |
197 ms |
380 KB |
Output is correct |
9 |
Correct |
201 ms |
508 KB |
Output is correct |
10 |
Correct |
201 ms |
504 KB |
Output is correct |
11 |
Correct |
17 ms |
376 KB |
Output is correct |
12 |
Correct |
139 ms |
376 KB |
Output is correct |
13 |
Correct |
109 ms |
376 KB |
Output is correct |
14 |
Correct |
116 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
535 ms |
468 KB |
Output is correct |
2 |
Correct |
764 ms |
464 KB |
Output is correct |
3 |
Correct |
272 ms |
504 KB |
Output is correct |
4 |
Correct |
197 ms |
376 KB |
Output is correct |
5 |
Correct |
73 ms |
504 KB |
Output is correct |
6 |
Correct |
182 ms |
532 KB |
Output is correct |
7 |
Correct |
109 ms |
376 KB |
Output is correct |
8 |
Correct |
197 ms |
380 KB |
Output is correct |
9 |
Correct |
201 ms |
508 KB |
Output is correct |
10 |
Correct |
201 ms |
504 KB |
Output is correct |
11 |
Correct |
17 ms |
376 KB |
Output is correct |
12 |
Correct |
139 ms |
376 KB |
Output is correct |
13 |
Correct |
109 ms |
376 KB |
Output is correct |
14 |
Correct |
116 ms |
504 KB |
Output is correct |
15 |
Correct |
451 ms |
472 KB |
Output is correct |
16 |
Correct |
179 ms |
460 KB |
Output is correct |
17 |
Correct |
243 ms |
504 KB |
Output is correct |
18 |
Correct |
200 ms |
564 KB |
Output is correct |
19 |
Correct |
201 ms |
476 KB |
Output is correct |
20 |
Correct |
204 ms |
504 KB |
Output is correct |
21 |
Correct |
203 ms |
476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
4 ms |
504 KB |
Output is correct |
13 |
Correct |
39 ms |
632 KB |
Output is correct |
14 |
Correct |
24 ms |
504 KB |
Output is correct |
15 |
Correct |
10 ms |
504 KB |
Output is correct |
16 |
Correct |
22 ms |
740 KB |
Output is correct |
17 |
Correct |
17 ms |
660 KB |
Output is correct |
18 |
Correct |
17 ms |
632 KB |
Output is correct |
19 |
Correct |
535 ms |
468 KB |
Output is correct |
20 |
Correct |
764 ms |
464 KB |
Output is correct |
21 |
Correct |
272 ms |
504 KB |
Output is correct |
22 |
Correct |
197 ms |
376 KB |
Output is correct |
23 |
Correct |
73 ms |
504 KB |
Output is correct |
24 |
Correct |
182 ms |
532 KB |
Output is correct |
25 |
Correct |
109 ms |
376 KB |
Output is correct |
26 |
Correct |
197 ms |
380 KB |
Output is correct |
27 |
Correct |
201 ms |
508 KB |
Output is correct |
28 |
Correct |
201 ms |
504 KB |
Output is correct |
29 |
Correct |
17 ms |
376 KB |
Output is correct |
30 |
Correct |
139 ms |
376 KB |
Output is correct |
31 |
Correct |
109 ms |
376 KB |
Output is correct |
32 |
Correct |
116 ms |
504 KB |
Output is correct |
33 |
Correct |
451 ms |
472 KB |
Output is correct |
34 |
Correct |
179 ms |
460 KB |
Output is correct |
35 |
Correct |
243 ms |
504 KB |
Output is correct |
36 |
Correct |
200 ms |
564 KB |
Output is correct |
37 |
Correct |
201 ms |
476 KB |
Output is correct |
38 |
Correct |
204 ms |
504 KB |
Output is correct |
39 |
Correct |
203 ms |
476 KB |
Output is correct |
40 |
Execution timed out |
3036 ms |
1016 KB |
Time limit exceeded |
41 |
Halted |
0 ms |
0 KB |
- |