#include<bits/stdc++.h>
using namespace std;
int main(){
int n,leng;
cin>>n>>leng;
int a[n+1];
for(int q=1;q<=n;q++){
cin>>a[q];
}
int q;
cin>>q;
pair<int,int>tny[q+1];
for(int w=1;w<=q;w++){
cin>>tny[w].first;
tny[w].second=w;
}
sort(tny+1,tny+q+1);
int pos[leng+1];
memset(pos,-1,sizeof pos);
for(int w=1;w<=q;w++){
if(pos[tny[w].first]==-1){
pos[tny[w].first]=w;
}
}
for(int w=leng-1;w>=0;w--){
if(pos[w]==-1){
pos[w]=pos[w+1];
}
}
int cnt[q+1][n+1];
memset(cnt,0,sizeof cnt);
for(int w=1;w<=n;w++){
int l=1,r=w+1;
int diff=0;
if(r+leng-1>n)break;
for(int j=0;j<leng;j++){
if(a[l+j]!=a[r+j]){
diff++;
}
}
cnt[pos[diff]][l]++;
cnt[pos[diff]][r]++;
while(r+leng<=n){
if(a[l+leng]!=a[r+leng]){
diff++;
}
if(a[l]!=a[r]){
diff--;
}
l++,r++;
cnt[pos[diff]][l]++;
cnt[pos[diff]][r]++;
}
}
for(int w=2;w<=q;w++){
for(int e=1;e<=n;e++){
cnt[w][e]+=cnt[w-1][e];
}
}
int ans[q+1][n+1];
for(int w=1;w<=q;w++){
for(int e=1;e<=n;e++){
ans[tny[w].second][e]=cnt[w][e];
}
}
for(int w=1;w<=q;w++){
for(int e=1;e<=n-leng+1;e++){
cout<<ans[w][e]<<" ";
}
cout<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
7 ms |
484 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
7 ms |
692 KB |
Output is correct |
17 |
Correct |
6 ms |
604 KB |
Output is correct |
18 |
Correct |
8 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
576 KB |
Output is correct |
2 |
Correct |
362 ms |
596 KB |
Output is correct |
3 |
Correct |
129 ms |
556 KB |
Output is correct |
4 |
Correct |
82 ms |
592 KB |
Output is correct |
5 |
Correct |
34 ms |
596 KB |
Output is correct |
6 |
Correct |
81 ms |
560 KB |
Output is correct |
7 |
Correct |
56 ms |
592 KB |
Output is correct |
8 |
Correct |
65 ms |
592 KB |
Output is correct |
9 |
Correct |
107 ms |
592 KB |
Output is correct |
10 |
Correct |
95 ms |
596 KB |
Output is correct |
11 |
Correct |
9 ms |
348 KB |
Output is correct |
12 |
Correct |
75 ms |
548 KB |
Output is correct |
13 |
Correct |
51 ms |
596 KB |
Output is correct |
14 |
Correct |
52 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
576 KB |
Output is correct |
2 |
Correct |
362 ms |
596 KB |
Output is correct |
3 |
Correct |
129 ms |
556 KB |
Output is correct |
4 |
Correct |
82 ms |
592 KB |
Output is correct |
5 |
Correct |
34 ms |
596 KB |
Output is correct |
6 |
Correct |
81 ms |
560 KB |
Output is correct |
7 |
Correct |
56 ms |
592 KB |
Output is correct |
8 |
Correct |
65 ms |
592 KB |
Output is correct |
9 |
Correct |
107 ms |
592 KB |
Output is correct |
10 |
Correct |
95 ms |
596 KB |
Output is correct |
11 |
Correct |
9 ms |
348 KB |
Output is correct |
12 |
Correct |
75 ms |
548 KB |
Output is correct |
13 |
Correct |
51 ms |
596 KB |
Output is correct |
14 |
Correct |
52 ms |
564 KB |
Output is correct |
15 |
Correct |
148 ms |
568 KB |
Output is correct |
16 |
Correct |
78 ms |
580 KB |
Output is correct |
17 |
Correct |
119 ms |
592 KB |
Output is correct |
18 |
Correct |
92 ms |
572 KB |
Output is correct |
19 |
Correct |
103 ms |
572 KB |
Output is correct |
20 |
Correct |
90 ms |
592 KB |
Output is correct |
21 |
Correct |
88 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
7 ms |
484 KB |
Output is correct |
14 |
Correct |
4 ms |
604 KB |
Output is correct |
15 |
Correct |
4 ms |
604 KB |
Output is correct |
16 |
Correct |
7 ms |
692 KB |
Output is correct |
17 |
Correct |
6 ms |
604 KB |
Output is correct |
18 |
Correct |
8 ms |
600 KB |
Output is correct |
19 |
Correct |
249 ms |
576 KB |
Output is correct |
20 |
Correct |
362 ms |
596 KB |
Output is correct |
21 |
Correct |
129 ms |
556 KB |
Output is correct |
22 |
Correct |
82 ms |
592 KB |
Output is correct |
23 |
Correct |
34 ms |
596 KB |
Output is correct |
24 |
Correct |
81 ms |
560 KB |
Output is correct |
25 |
Correct |
56 ms |
592 KB |
Output is correct |
26 |
Correct |
65 ms |
592 KB |
Output is correct |
27 |
Correct |
107 ms |
592 KB |
Output is correct |
28 |
Correct |
95 ms |
596 KB |
Output is correct |
29 |
Correct |
9 ms |
348 KB |
Output is correct |
30 |
Correct |
75 ms |
548 KB |
Output is correct |
31 |
Correct |
51 ms |
596 KB |
Output is correct |
32 |
Correct |
52 ms |
564 KB |
Output is correct |
33 |
Correct |
148 ms |
568 KB |
Output is correct |
34 |
Correct |
78 ms |
580 KB |
Output is correct |
35 |
Correct |
119 ms |
592 KB |
Output is correct |
36 |
Correct |
92 ms |
572 KB |
Output is correct |
37 |
Correct |
103 ms |
572 KB |
Output is correct |
38 |
Correct |
90 ms |
592 KB |
Output is correct |
39 |
Correct |
88 ms |
564 KB |
Output is correct |
40 |
Correct |
422 ms |
2896 KB |
Output is correct |
41 |
Correct |
9 ms |
2140 KB |
Output is correct |
42 |
Correct |
134 ms |
2852 KB |
Output is correct |
43 |
Correct |
98 ms |
2384 KB |
Output is correct |
44 |
Correct |
99 ms |
2604 KB |
Output is correct |
45 |
Correct |
480 ms |
12076 KB |
Output is correct |
46 |
Correct |
16 ms |
8536 KB |
Output is correct |
47 |
Correct |
162 ms |
12112 KB |
Output is correct |
48 |
Correct |
139 ms |
10328 KB |
Output is correct |
49 |
Correct |
134 ms |
11088 KB |
Output is correct |