#include<bits/stdc++.h>
#define MAXN 10007
using namespace std;
int n,l,q;
int a[MAXN];
pair<int,int> k[MAXN];
int br[MAXN][107],matches,to[MAXN],ans[MAXN],pos[MAXN];
int calc(int x,int y){
int res=0;
for(int i=0;i<l;i++){
if(a[x+i]==a[y+i])res++;
}
return res;
}
int main(){
cin>>n>>l;
for(int i=1;i<=n;i++){
cin>>a[i];
}
cin>>q;
for(int i=1;i<=q;i++){
cin>>k[i].first;
k[i].first=l-k[i].first;
k[i].second=i;
}
sort(k+1,k+q+1);
for(int i=1;i<=q;i++){
pos[k[i].second]=i;
}
int pt=0;
for(int i=0;i<=l;i++){
while(pt<q and k[pt+1].first<=i)pt++;
to[i]=pt;
}
for(int dist=1;dist<=n;dist++){
for(int i=1;i+dist+l-1<=n;i++){
if(i==1)matches=calc(i,i+dist);
else{
if(a[i-1]==a[i+dist-1])matches--;
if(a[i+l-1]==a[i+dist+l-1])matches++;
}
br[i][to[matches]]++;
br[i+dist][to[matches]]++;
}
}
for(int i=1;i<=n;i++){
for(int f=q-1;f>=1;f--){
br[i][f]+=br[i][f+1];
}
}
for(int i=1;i<=q;i++){
for(int f=1;f+l-1<=n;f++){
cout<<br[f][pos[i]]<<" ";
}
cout<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 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 |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 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 |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
8 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1372 KB |
Output is correct |
16 |
Correct |
7 ms |
1372 KB |
Output is correct |
17 |
Correct |
7 ms |
1368 KB |
Output is correct |
18 |
Correct |
6 ms |
1348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
4688 KB |
Output is correct |
2 |
Correct |
379 ms |
4688 KB |
Output is correct |
3 |
Correct |
190 ms |
4696 KB |
Output is correct |
4 |
Correct |
167 ms |
4688 KB |
Output is correct |
5 |
Correct |
54 ms |
2648 KB |
Output is correct |
6 |
Correct |
143 ms |
4444 KB |
Output is correct |
7 |
Correct |
56 ms |
2652 KB |
Output is correct |
8 |
Correct |
89 ms |
3416 KB |
Output is correct |
9 |
Correct |
165 ms |
4628 KB |
Output is correct |
10 |
Correct |
157 ms |
4688 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
89 ms |
3420 KB |
Output is correct |
13 |
Correct |
71 ms |
3160 KB |
Output is correct |
14 |
Correct |
73 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
336 ms |
4688 KB |
Output is correct |
2 |
Correct |
379 ms |
4688 KB |
Output is correct |
3 |
Correct |
190 ms |
4696 KB |
Output is correct |
4 |
Correct |
167 ms |
4688 KB |
Output is correct |
5 |
Correct |
54 ms |
2648 KB |
Output is correct |
6 |
Correct |
143 ms |
4444 KB |
Output is correct |
7 |
Correct |
56 ms |
2652 KB |
Output is correct |
8 |
Correct |
89 ms |
3416 KB |
Output is correct |
9 |
Correct |
165 ms |
4628 KB |
Output is correct |
10 |
Correct |
157 ms |
4688 KB |
Output is correct |
11 |
Correct |
9 ms |
1116 KB |
Output is correct |
12 |
Correct |
89 ms |
3420 KB |
Output is correct |
13 |
Correct |
71 ms |
3160 KB |
Output is correct |
14 |
Correct |
73 ms |
2908 KB |
Output is correct |
15 |
Correct |
208 ms |
4544 KB |
Output is correct |
16 |
Correct |
142 ms |
4188 KB |
Output is correct |
17 |
Correct |
172 ms |
4696 KB |
Output is correct |
18 |
Correct |
158 ms |
4700 KB |
Output is correct |
19 |
Correct |
161 ms |
4648 KB |
Output is correct |
20 |
Correct |
166 ms |
4736 KB |
Output is correct |
21 |
Correct |
156 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
444 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 |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
8 ms |
1112 KB |
Output is correct |
14 |
Correct |
6 ms |
1372 KB |
Output is correct |
15 |
Correct |
4 ms |
1372 KB |
Output is correct |
16 |
Correct |
7 ms |
1372 KB |
Output is correct |
17 |
Correct |
7 ms |
1368 KB |
Output is correct |
18 |
Correct |
6 ms |
1348 KB |
Output is correct |
19 |
Correct |
336 ms |
4688 KB |
Output is correct |
20 |
Correct |
379 ms |
4688 KB |
Output is correct |
21 |
Correct |
190 ms |
4696 KB |
Output is correct |
22 |
Correct |
167 ms |
4688 KB |
Output is correct |
23 |
Correct |
54 ms |
2648 KB |
Output is correct |
24 |
Correct |
143 ms |
4444 KB |
Output is correct |
25 |
Correct |
56 ms |
2652 KB |
Output is correct |
26 |
Correct |
89 ms |
3416 KB |
Output is correct |
27 |
Correct |
165 ms |
4628 KB |
Output is correct |
28 |
Correct |
157 ms |
4688 KB |
Output is correct |
29 |
Correct |
9 ms |
1116 KB |
Output is correct |
30 |
Correct |
89 ms |
3420 KB |
Output is correct |
31 |
Correct |
71 ms |
3160 KB |
Output is correct |
32 |
Correct |
73 ms |
2908 KB |
Output is correct |
33 |
Correct |
208 ms |
4544 KB |
Output is correct |
34 |
Correct |
142 ms |
4188 KB |
Output is correct |
35 |
Correct |
172 ms |
4696 KB |
Output is correct |
36 |
Correct |
158 ms |
4700 KB |
Output is correct |
37 |
Correct |
161 ms |
4648 KB |
Output is correct |
38 |
Correct |
166 ms |
4736 KB |
Output is correct |
39 |
Correct |
156 ms |
4696 KB |
Output is correct |
40 |
Correct |
526 ms |
5492 KB |
Output is correct |
41 |
Correct |
14 ms |
4700 KB |
Output is correct |
42 |
Correct |
170 ms |
5424 KB |
Output is correct |
43 |
Correct |
158 ms |
4944 KB |
Output is correct |
44 |
Correct |
160 ms |
5200 KB |
Output is correct |
45 |
Correct |
569 ms |
8528 KB |
Output is correct |
46 |
Correct |
18 ms |
4956 KB |
Output is correct |
47 |
Correct |
208 ms |
8532 KB |
Output is correct |
48 |
Correct |
198 ms |
6880 KB |
Output is correct |
49 |
Correct |
206 ms |
7408 KB |
Output is correct |