#include <bits/stdc++.h>
using namespace std;
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int ll;
#define all(a) a.begin(),a.end()
int a[10005],b[10005];
int ans[105][10005];
int nearest[10005];
int main()
{
owo
int n,l;
cin>>n>>l;
for(int i=0;i<n;i++)cin>>a[i];
int q;
cin>>q;
vector<array<int,2>>qu;
for(int i=0;i<q;i++){
int k;
cin>>k;
qu.push_back({l-k,i});
//>=l-k matches
}
sort(all(qu));
for(int i=0;i<=n;i++){
nearest[i] = -1;
for(int j=0;j<q;j++){
if(i >= qu[j][0])nearest[i] = j;
}
//cout<<nearest[i]<<" ";
}
//cout<<'\n';
for(int i=-n+1;i<n;i++){
if(i==0)continue;
for(int j=0;j<n;j++){
if(j+i>=0 && j+i<n && a[j] == a[i+j])b[j] = 1;
}
for(int j=1;j<n;j++)b[j]+=b[j-1];
for(int j=max(0,-i);j<min(n-l+1,n-l-i+1);j++){ //i am shiftng by i
int num = b[j+l-1] - (j?b[j-1]:0);
//for(int k=0;k<q;k++)if(num >= qu[k][0])ans[qu[k][1]][j]++;
if(nearest[num] != -1){
int idx = nearest[num];
ans[idx][j]++;
}
}
for(int j=0;j<n;j++)b[j] = 0;
}
for(int i=q-2;i>=0;i--){
for(int j=0;j<n;j++)ans[i][j]+=ans[i+1][j];
}
for(int i=0;i<q;i++){
for(int j=0;j<q;j++){
if(qu[j][1] == i){
for(int k=0;k<n-l+1;k++)cout<<ans[j][k]<<" ";
cout<<'\n';
break;
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
56 ms |
400 KB |
Output is correct |
14 |
Correct |
40 ms |
588 KB |
Output is correct |
15 |
Correct |
30 ms |
488 KB |
Output is correct |
16 |
Correct |
33 ms |
668 KB |
Output is correct |
17 |
Correct |
31 ms |
576 KB |
Output is correct |
18 |
Correct |
31 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1347 ms |
700 KB |
Output is correct |
2 |
Correct |
1211 ms |
460 KB |
Output is correct |
3 |
Correct |
827 ms |
456 KB |
Output is correct |
4 |
Correct |
723 ms |
456 KB |
Output is correct |
5 |
Correct |
648 ms |
556 KB |
Output is correct |
6 |
Correct |
698 ms |
560 KB |
Output is correct |
7 |
Correct |
764 ms |
424 KB |
Output is correct |
8 |
Correct |
909 ms |
556 KB |
Output is correct |
9 |
Correct |
730 ms |
464 KB |
Output is correct |
10 |
Correct |
728 ms |
560 KB |
Output is correct |
11 |
Correct |
65 ms |
352 KB |
Output is correct |
12 |
Correct |
554 ms |
552 KB |
Output is correct |
13 |
Correct |
651 ms |
548 KB |
Output is correct |
14 |
Correct |
670 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1347 ms |
700 KB |
Output is correct |
2 |
Correct |
1211 ms |
460 KB |
Output is correct |
3 |
Correct |
827 ms |
456 KB |
Output is correct |
4 |
Correct |
723 ms |
456 KB |
Output is correct |
5 |
Correct |
648 ms |
556 KB |
Output is correct |
6 |
Correct |
698 ms |
560 KB |
Output is correct |
7 |
Correct |
764 ms |
424 KB |
Output is correct |
8 |
Correct |
909 ms |
556 KB |
Output is correct |
9 |
Correct |
730 ms |
464 KB |
Output is correct |
10 |
Correct |
728 ms |
560 KB |
Output is correct |
11 |
Correct |
65 ms |
352 KB |
Output is correct |
12 |
Correct |
554 ms |
552 KB |
Output is correct |
13 |
Correct |
651 ms |
548 KB |
Output is correct |
14 |
Correct |
670 ms |
548 KB |
Output is correct |
15 |
Correct |
1109 ms |
460 KB |
Output is correct |
16 |
Correct |
727 ms |
452 KB |
Output is correct |
17 |
Correct |
761 ms |
460 KB |
Output is correct |
18 |
Correct |
709 ms |
460 KB |
Output is correct |
19 |
Correct |
733 ms |
460 KB |
Output is correct |
20 |
Correct |
737 ms |
460 KB |
Output is correct |
21 |
Correct |
729 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
56 ms |
400 KB |
Output is correct |
14 |
Correct |
40 ms |
588 KB |
Output is correct |
15 |
Correct |
30 ms |
488 KB |
Output is correct |
16 |
Correct |
33 ms |
668 KB |
Output is correct |
17 |
Correct |
31 ms |
576 KB |
Output is correct |
18 |
Correct |
31 ms |
596 KB |
Output is correct |
19 |
Correct |
1347 ms |
700 KB |
Output is correct |
20 |
Correct |
1211 ms |
460 KB |
Output is correct |
21 |
Correct |
827 ms |
456 KB |
Output is correct |
22 |
Correct |
723 ms |
456 KB |
Output is correct |
23 |
Correct |
648 ms |
556 KB |
Output is correct |
24 |
Correct |
698 ms |
560 KB |
Output is correct |
25 |
Correct |
764 ms |
424 KB |
Output is correct |
26 |
Correct |
909 ms |
556 KB |
Output is correct |
27 |
Correct |
730 ms |
464 KB |
Output is correct |
28 |
Correct |
728 ms |
560 KB |
Output is correct |
29 |
Correct |
65 ms |
352 KB |
Output is correct |
30 |
Correct |
554 ms |
552 KB |
Output is correct |
31 |
Correct |
651 ms |
548 KB |
Output is correct |
32 |
Correct |
670 ms |
548 KB |
Output is correct |
33 |
Correct |
1109 ms |
460 KB |
Output is correct |
34 |
Correct |
727 ms |
452 KB |
Output is correct |
35 |
Correct |
761 ms |
460 KB |
Output is correct |
36 |
Correct |
709 ms |
460 KB |
Output is correct |
37 |
Correct |
733 ms |
460 KB |
Output is correct |
38 |
Correct |
737 ms |
460 KB |
Output is correct |
39 |
Correct |
729 ms |
460 KB |
Output is correct |
40 |
Correct |
1687 ms |
1932 KB |
Output is correct |
41 |
Correct |
683 ms |
1308 KB |
Output is correct |
42 |
Correct |
866 ms |
1904 KB |
Output is correct |
43 |
Correct |
737 ms |
1776 KB |
Output is correct |
44 |
Correct |
752 ms |
1884 KB |
Output is correct |
45 |
Correct |
1814 ms |
8128 KB |
Output is correct |
46 |
Correct |
670 ms |
4628 KB |
Output is correct |
47 |
Correct |
1335 ms |
8396 KB |
Output is correct |
48 |
Correct |
915 ms |
6548 KB |
Output is correct |
49 |
Correct |
791 ms |
7244 KB |
Output is correct |