#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,l,q;
cin>>n>>l;
vector <int> a(n+1);
for(int i=1;i<=n;i++)cin>>a[i];
cin>>q;
vector <int> k(q),v;
for(int i=0;i<q;i++){
cin>>k[i];
v.pb(k[i]);
}
sort(all(v));
vector <vector <int> > ans(n+1,vector <int> (q));
for(int i=1;i<=n;i++){
if(i+l-1<=n){
int res=0;
int ind=1;
for(int j=i;j<i+l;j++){
res+=(a[ind]!=a[j]);
ind++;
}
auto it=lower_bound(all(v),res);
if(it!=v.end())ans[1][it-v.begin()]++;
int x=2,y=i+1;
while(x<=n && y<=n && x+l-1<=n && y+l-1<=n){
int new_res=res-(a[x-1]!=a[y-1])+(a[x+l-1]!=a[y+l-1]);
res=new_res;
auto it=lower_bound(all(v),res);
if(it!=v.end())ans[x][it-v.begin()]++;
x++;
y++;
}
}
}
for(int i=2;i<=n;i++){
if(i+l-1<=n){
int res=0;
int ind=1;
for(int j=i;j<i+l;j++){
res+=(a[ind]!=a[j]);
ind++;
}
auto it=lower_bound(all(v),res);
if(it!=v.end())ans[i][it-v.begin()]++;
int x=i+1,y=2;
while(x<=n && y<=n && x+l-1<=n && y+l-1<=n){
int new_res=res-(a[x-1]!=a[y-1])+(a[x+l-1]!=a[y+l-1]);
res=new_res;
auto it=lower_bound(all(v),res);
if(it!=v.end())ans[x][it-v.begin()]++;
x++;
y++;
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<q;j++)ans[i][j]+=ans[i][j-1];
}
for(int i=0;i<q;i++){
auto pos=lower_bound(all(v),k[i])-v.begin();
for(int j=1;j<=n-l+1;j++){
cout<<ans[j][pos]-1<<" ";
}
cout<<"\n";
}
}
/*
6 2
1 2 1 3 2 1
2
1
2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
13 |
Correct |
27 ms |
604 KB |
Output is correct |
14 |
Correct |
16 ms |
860 KB |
Output is correct |
15 |
Correct |
12 ms |
604 KB |
Output is correct |
16 |
Correct |
25 ms |
856 KB |
Output is correct |
17 |
Correct |
18 ms |
1112 KB |
Output is correct |
18 |
Correct |
18 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
561 ms |
1068 KB |
Output is correct |
2 |
Correct |
399 ms |
1064 KB |
Output is correct |
3 |
Correct |
388 ms |
1068 KB |
Output is correct |
4 |
Correct |
362 ms |
1164 KB |
Output is correct |
5 |
Correct |
142 ms |
1360 KB |
Output is correct |
6 |
Correct |
332 ms |
1168 KB |
Output is correct |
7 |
Correct |
130 ms |
1112 KB |
Output is correct |
8 |
Correct |
234 ms |
1144 KB |
Output is correct |
9 |
Correct |
356 ms |
1148 KB |
Output is correct |
10 |
Correct |
380 ms |
1364 KB |
Output is correct |
11 |
Correct |
18 ms |
604 KB |
Output is correct |
12 |
Correct |
203 ms |
1068 KB |
Output is correct |
13 |
Correct |
162 ms |
1116 KB |
Output is correct |
14 |
Correct |
161 ms |
1148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
561 ms |
1068 KB |
Output is correct |
2 |
Correct |
399 ms |
1064 KB |
Output is correct |
3 |
Correct |
388 ms |
1068 KB |
Output is correct |
4 |
Correct |
362 ms |
1164 KB |
Output is correct |
5 |
Correct |
142 ms |
1360 KB |
Output is correct |
6 |
Correct |
332 ms |
1168 KB |
Output is correct |
7 |
Correct |
130 ms |
1112 KB |
Output is correct |
8 |
Correct |
234 ms |
1144 KB |
Output is correct |
9 |
Correct |
356 ms |
1148 KB |
Output is correct |
10 |
Correct |
380 ms |
1364 KB |
Output is correct |
11 |
Correct |
18 ms |
604 KB |
Output is correct |
12 |
Correct |
203 ms |
1068 KB |
Output is correct |
13 |
Correct |
162 ms |
1116 KB |
Output is correct |
14 |
Correct |
161 ms |
1148 KB |
Output is correct |
15 |
Correct |
383 ms |
1072 KB |
Output is correct |
16 |
Correct |
320 ms |
1144 KB |
Output is correct |
17 |
Correct |
381 ms |
1148 KB |
Output is correct |
18 |
Correct |
379 ms |
1360 KB |
Output is correct |
19 |
Correct |
369 ms |
1152 KB |
Output is correct |
20 |
Correct |
382 ms |
1364 KB |
Output is correct |
21 |
Correct |
384 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
13 |
Correct |
27 ms |
604 KB |
Output is correct |
14 |
Correct |
16 ms |
860 KB |
Output is correct |
15 |
Correct |
12 ms |
604 KB |
Output is correct |
16 |
Correct |
25 ms |
856 KB |
Output is correct |
17 |
Correct |
18 ms |
1112 KB |
Output is correct |
18 |
Correct |
18 ms |
856 KB |
Output is correct |
19 |
Correct |
561 ms |
1068 KB |
Output is correct |
20 |
Correct |
399 ms |
1064 KB |
Output is correct |
21 |
Correct |
388 ms |
1068 KB |
Output is correct |
22 |
Correct |
362 ms |
1164 KB |
Output is correct |
23 |
Correct |
142 ms |
1360 KB |
Output is correct |
24 |
Correct |
332 ms |
1168 KB |
Output is correct |
25 |
Correct |
130 ms |
1112 KB |
Output is correct |
26 |
Correct |
234 ms |
1144 KB |
Output is correct |
27 |
Correct |
356 ms |
1148 KB |
Output is correct |
28 |
Correct |
380 ms |
1364 KB |
Output is correct |
29 |
Correct |
18 ms |
604 KB |
Output is correct |
30 |
Correct |
203 ms |
1068 KB |
Output is correct |
31 |
Correct |
162 ms |
1116 KB |
Output is correct |
32 |
Correct |
161 ms |
1148 KB |
Output is correct |
33 |
Correct |
383 ms |
1072 KB |
Output is correct |
34 |
Correct |
320 ms |
1144 KB |
Output is correct |
35 |
Correct |
381 ms |
1148 KB |
Output is correct |
36 |
Correct |
379 ms |
1360 KB |
Output is correct |
37 |
Correct |
369 ms |
1152 KB |
Output is correct |
38 |
Correct |
382 ms |
1364 KB |
Output is correct |
39 |
Correct |
384 ms |
1112 KB |
Output is correct |
40 |
Correct |
877 ms |
3256 KB |
Output is correct |
41 |
Correct |
23 ms |
2652 KB |
Output is correct |
42 |
Correct |
574 ms |
3260 KB |
Output is correct |
43 |
Correct |
531 ms |
2816 KB |
Output is correct |
44 |
Correct |
556 ms |
3068 KB |
Output is correct |
45 |
Correct |
1580 ms |
12392 KB |
Output is correct |
46 |
Correct |
31 ms |
9044 KB |
Output is correct |
47 |
Correct |
990 ms |
12588 KB |
Output is correct |
48 |
Correct |
765 ms |
10872 KB |
Output is correct |
49 |
Correct |
705 ms |
11384 KB |
Output is correct |