#include <bits/stdc++.h>
using namespace std;
const int N = 1e4+1, Q = 1e2+1;
int a[N],id[N];
int diff[N], ans[N][Q], res[N][Q];
pair<int,int> queries[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,l;
cin >> n >> l;
for (int i=0; i<n; ++i){
cin >> a[i];
}
int q;
cin >> q;
for (int i=0; i<q; ++i){
cin >> queries[i].first;
queries[i].second = i;
}
sort(queries,queries+q);
int idx = 0;
for (int i=0; i<=n; ++i){
while (idx < q and queries[idx].first < i) idx++;
id[i] = idx;
}
for (int i=1; i<n-l+1; ++i){
for (int j=0; j<l; ++j){
if (a[i+j] != a[j]) diff[i]++;
}
ans[0][id[diff[i]]]++;
ans[i][id[diff[i]]]++;
}
for (int i=1; i<n-l+1; ++i){
for (int j=n-l; j>=i+1; --j){
diff[j] = diff[j-1]-(a[i-1] != a[j-1])+(a[i+l-1] != a[j+l-1]);
ans[i][id[diff[j]]]++;
ans[j][id[diff[j]]]++;
}
}
for (int i=0; i<n; ++i){
res[i][queries[0].second] = ans[i][0];
for (int j=1; j<q; ++j){
ans[i][j] += ans[i][j-1];
res[i][queries[j].second] = ans[i][j];
}
}
for (int j=0; j<q; ++j){
for (int i=0; i<n-l+1; ++i) cout << res[i][j] << ' ';
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
16 ms |
1928 KB |
Output is correct |
14 |
Correct |
10 ms |
1948 KB |
Output is correct |
15 |
Correct |
10 ms |
1944 KB |
Output is correct |
16 |
Correct |
16 ms |
2012 KB |
Output is correct |
17 |
Correct |
14 ms |
2016 KB |
Output is correct |
18 |
Correct |
19 ms |
1948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
390 ms |
8376 KB |
Output is correct |
2 |
Correct |
394 ms |
8368 KB |
Output is correct |
3 |
Correct |
390 ms |
8368 KB |
Output is correct |
4 |
Correct |
384 ms |
8368 KB |
Output is correct |
5 |
Correct |
125 ms |
6336 KB |
Output is correct |
6 |
Correct |
379 ms |
8172 KB |
Output is correct |
7 |
Correct |
132 ms |
6536 KB |
Output is correct |
8 |
Correct |
234 ms |
7264 KB |
Output is correct |
9 |
Correct |
374 ms |
8316 KB |
Output is correct |
10 |
Correct |
370 ms |
8372 KB |
Output is correct |
11 |
Correct |
19 ms |
2324 KB |
Output is correct |
12 |
Correct |
191 ms |
6724 KB |
Output is correct |
13 |
Correct |
159 ms |
6700 KB |
Output is correct |
14 |
Correct |
162 ms |
6824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
390 ms |
8376 KB |
Output is correct |
2 |
Correct |
394 ms |
8368 KB |
Output is correct |
3 |
Correct |
390 ms |
8368 KB |
Output is correct |
4 |
Correct |
384 ms |
8368 KB |
Output is correct |
5 |
Correct |
125 ms |
6336 KB |
Output is correct |
6 |
Correct |
379 ms |
8172 KB |
Output is correct |
7 |
Correct |
132 ms |
6536 KB |
Output is correct |
8 |
Correct |
234 ms |
7264 KB |
Output is correct |
9 |
Correct |
374 ms |
8316 KB |
Output is correct |
10 |
Correct |
370 ms |
8372 KB |
Output is correct |
11 |
Correct |
19 ms |
2324 KB |
Output is correct |
12 |
Correct |
191 ms |
6724 KB |
Output is correct |
13 |
Correct |
159 ms |
6700 KB |
Output is correct |
14 |
Correct |
162 ms |
6824 KB |
Output is correct |
15 |
Correct |
354 ms |
8248 KB |
Output is correct |
16 |
Correct |
339 ms |
8056 KB |
Output is correct |
17 |
Correct |
376 ms |
8440 KB |
Output is correct |
18 |
Correct |
381 ms |
8412 KB |
Output is correct |
19 |
Correct |
378 ms |
8412 KB |
Output is correct |
20 |
Correct |
385 ms |
8412 KB |
Output is correct |
21 |
Correct |
367 ms |
8412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
580 KB |
Output is correct |
12 |
Correct |
3 ms |
596 KB |
Output is correct |
13 |
Correct |
16 ms |
1928 KB |
Output is correct |
14 |
Correct |
10 ms |
1948 KB |
Output is correct |
15 |
Correct |
10 ms |
1944 KB |
Output is correct |
16 |
Correct |
16 ms |
2012 KB |
Output is correct |
17 |
Correct |
14 ms |
2016 KB |
Output is correct |
18 |
Correct |
19 ms |
1948 KB |
Output is correct |
19 |
Correct |
390 ms |
8376 KB |
Output is correct |
20 |
Correct |
394 ms |
8368 KB |
Output is correct |
21 |
Correct |
390 ms |
8368 KB |
Output is correct |
22 |
Correct |
384 ms |
8368 KB |
Output is correct |
23 |
Correct |
125 ms |
6336 KB |
Output is correct |
24 |
Correct |
379 ms |
8172 KB |
Output is correct |
25 |
Correct |
132 ms |
6536 KB |
Output is correct |
26 |
Correct |
234 ms |
7264 KB |
Output is correct |
27 |
Correct |
374 ms |
8316 KB |
Output is correct |
28 |
Correct |
370 ms |
8372 KB |
Output is correct |
29 |
Correct |
19 ms |
2324 KB |
Output is correct |
30 |
Correct |
191 ms |
6724 KB |
Output is correct |
31 |
Correct |
159 ms |
6700 KB |
Output is correct |
32 |
Correct |
162 ms |
6824 KB |
Output is correct |
33 |
Correct |
354 ms |
8248 KB |
Output is correct |
34 |
Correct |
339 ms |
8056 KB |
Output is correct |
35 |
Correct |
376 ms |
8440 KB |
Output is correct |
36 |
Correct |
381 ms |
8412 KB |
Output is correct |
37 |
Correct |
378 ms |
8412 KB |
Output is correct |
38 |
Correct |
385 ms |
8412 KB |
Output is correct |
39 |
Correct |
367 ms |
8412 KB |
Output is correct |
40 |
Correct |
394 ms |
9160 KB |
Output is correct |
41 |
Correct |
19 ms |
8476 KB |
Output is correct |
42 |
Correct |
387 ms |
9100 KB |
Output is correct |
43 |
Correct |
365 ms |
8788 KB |
Output is correct |
44 |
Correct |
357 ms |
8920 KB |
Output is correct |
45 |
Correct |
471 ms |
12100 KB |
Output is correct |
46 |
Correct |
27 ms |
8728 KB |
Output is correct |
47 |
Correct |
465 ms |
12312 KB |
Output is correct |
48 |
Correct |
425 ms |
10448 KB |
Output is correct |
49 |
Correct |
426 ms |
11260 KB |
Output is correct |