#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e4+10;
const lint LNF = 2e18;
/*
i + c = x;
j + c = y;
j = y - c = y - x + i;
for each substring i:
if i<=x<i+l A[x] is same as A[y]: cnt[y-x+i]++;
then, do tmp[y-x]++ for all A[x]=A[y];
then cnt[z+i] = tmp[z];
*/
int n, m, l, q, A[MAX], K[101], ans[101][MAX], tmp[MAX*2], cnt[MAX], sum[MAX];
void upt(int i, int v){
for(int j=1; j<=n; j++) if(A[i]==A[j]) tmp[j-i+10000]+=v;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>l; m=n-l+1;
for(int i=1; i<=n; i++) cin>>A[i];
cin>>q;
for(int i=1; i<=q; i++) cin>>K[i];
for(int i=1, lft=1, rig=0; i<=m; i++){
while(rig<i+l-1){ upt(++rig, 1); }
while(lft<i){ upt(lft++, -1); }
for(int j=1; j<=m; j++) cnt[j] = l-tmp[j-i+10000];
fill(sum, sum+l+1, 0);
for(int j=1; j<=m; j++) if(j!=i) sum[cnt[j]]++;
for(int j=1; j<=l; j++) sum[j]+=sum[j-1];
for(int j=1; j<=q; j++) ans[j][i] = sum[K[j]];
}
for(int i=1; i<=q; i++, cout<<'\n') for(int j=1; j<=m; j++) cout<<ans[i][j]<<' ';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
24 ms |
512 KB |
Output is correct |
14 |
Correct |
16 ms |
632 KB |
Output is correct |
15 |
Correct |
16 ms |
512 KB |
Output is correct |
16 |
Correct |
21 ms |
760 KB |
Output is correct |
17 |
Correct |
19 ms |
768 KB |
Output is correct |
18 |
Correct |
19 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1097 ms |
760 KB |
Output is correct |
2 |
Correct |
1107 ms |
916 KB |
Output is correct |
3 |
Correct |
581 ms |
636 KB |
Output is correct |
4 |
Correct |
436 ms |
912 KB |
Output is correct |
5 |
Correct |
224 ms |
760 KB |
Output is correct |
6 |
Correct |
407 ms |
904 KB |
Output is correct |
7 |
Correct |
280 ms |
760 KB |
Output is correct |
8 |
Correct |
358 ms |
888 KB |
Output is correct |
9 |
Correct |
437 ms |
760 KB |
Output is correct |
10 |
Correct |
441 ms |
860 KB |
Output is correct |
11 |
Correct |
30 ms |
384 KB |
Output is correct |
12 |
Correct |
278 ms |
632 KB |
Output is correct |
13 |
Correct |
296 ms |
780 KB |
Output is correct |
14 |
Correct |
295 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1097 ms |
760 KB |
Output is correct |
2 |
Correct |
1107 ms |
916 KB |
Output is correct |
3 |
Correct |
581 ms |
636 KB |
Output is correct |
4 |
Correct |
436 ms |
912 KB |
Output is correct |
5 |
Correct |
224 ms |
760 KB |
Output is correct |
6 |
Correct |
407 ms |
904 KB |
Output is correct |
7 |
Correct |
280 ms |
760 KB |
Output is correct |
8 |
Correct |
358 ms |
888 KB |
Output is correct |
9 |
Correct |
437 ms |
760 KB |
Output is correct |
10 |
Correct |
441 ms |
860 KB |
Output is correct |
11 |
Correct |
30 ms |
384 KB |
Output is correct |
12 |
Correct |
278 ms |
632 KB |
Output is correct |
13 |
Correct |
296 ms |
780 KB |
Output is correct |
14 |
Correct |
295 ms |
732 KB |
Output is correct |
15 |
Correct |
481 ms |
852 KB |
Output is correct |
16 |
Correct |
430 ms |
768 KB |
Output is correct |
17 |
Correct |
436 ms |
908 KB |
Output is correct |
18 |
Correct |
421 ms |
784 KB |
Output is correct |
19 |
Correct |
428 ms |
800 KB |
Output is correct |
20 |
Correct |
421 ms |
760 KB |
Output is correct |
21 |
Correct |
447 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
3 ms |
512 KB |
Output is correct |
13 |
Correct |
24 ms |
512 KB |
Output is correct |
14 |
Correct |
16 ms |
632 KB |
Output is correct |
15 |
Correct |
16 ms |
512 KB |
Output is correct |
16 |
Correct |
21 ms |
760 KB |
Output is correct |
17 |
Correct |
19 ms |
768 KB |
Output is correct |
18 |
Correct |
19 ms |
760 KB |
Output is correct |
19 |
Correct |
1097 ms |
760 KB |
Output is correct |
20 |
Correct |
1107 ms |
916 KB |
Output is correct |
21 |
Correct |
581 ms |
636 KB |
Output is correct |
22 |
Correct |
436 ms |
912 KB |
Output is correct |
23 |
Correct |
224 ms |
760 KB |
Output is correct |
24 |
Correct |
407 ms |
904 KB |
Output is correct |
25 |
Correct |
280 ms |
760 KB |
Output is correct |
26 |
Correct |
358 ms |
888 KB |
Output is correct |
27 |
Correct |
437 ms |
760 KB |
Output is correct |
28 |
Correct |
441 ms |
860 KB |
Output is correct |
29 |
Correct |
30 ms |
384 KB |
Output is correct |
30 |
Correct |
278 ms |
632 KB |
Output is correct |
31 |
Correct |
296 ms |
780 KB |
Output is correct |
32 |
Correct |
295 ms |
732 KB |
Output is correct |
33 |
Correct |
481 ms |
852 KB |
Output is correct |
34 |
Correct |
430 ms |
768 KB |
Output is correct |
35 |
Correct |
436 ms |
908 KB |
Output is correct |
36 |
Correct |
421 ms |
784 KB |
Output is correct |
37 |
Correct |
428 ms |
800 KB |
Output is correct |
38 |
Correct |
421 ms |
760 KB |
Output is correct |
39 |
Correct |
447 ms |
896 KB |
Output is correct |
40 |
Correct |
1130 ms |
2172 KB |
Output is correct |
41 |
Correct |
149 ms |
860 KB |
Output is correct |
42 |
Correct |
383 ms |
2268 KB |
Output is correct |
43 |
Correct |
428 ms |
2040 KB |
Output is correct |
44 |
Correct |
424 ms |
2044 KB |
Output is correct |
45 |
Correct |
1183 ms |
8312 KB |
Output is correct |
46 |
Correct |
158 ms |
1656 KB |
Output is correct |
47 |
Correct |
523 ms |
8388 KB |
Output is correct |
48 |
Correct |
473 ms |
6664 KB |
Output is correct |
49 |
Correct |
477 ms |
7288 KB |
Output is correct |