#include <bits/stdc++.h>
using namespace std;
#define LCBorz \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define x first
#define y second
//#define endl '\n'
const int N=100005;
const int INF=1e18;
int32_t main() {
LCBorz;
int n,k;cin>>n>>k;
vector<int> v(n);
for(int i=0;i<n;i++){
cin>>v[i];
}
int q;cin>>q;
int ans[n+1][q+2]{};
vector<pair<int,int>> ask(q+2);
for(int i=1;i<=q;i++){
cin>>ask[i].first;
ask[i].second=i;
}
ask[0]={0,0};
ask[q+1]={n,n};
sort(all(ask));
int idx=1;
for(int i=1;i<n;i++){
vector<int> a;
//a.push_back(0);
for(int j=0;j+i<n;j++){
a.push_back(v[j]!=v[i+j]);
}
int sz=a.size();
if(sz<k){
continue;
}
int cnt=0;
for(int j=0;j<k;j++){
cnt+=a[j];
}
//cout<<0<<' '<<i<<' '<<cnt<<endl;
while(idx&&ask[idx-1].first>=cnt){
//cout<<"flag1"<<endl;
idx--;
}
while(ask[idx].first<cnt){
//cout<<"flag2"<<endl;
idx++;
}
ans[0][idx]++;
ans[i][idx]++;
for(int j=k;j<sz;j++){
cnt-=a[j-k];
cnt+=a[j];
while(idx&&ask[idx-1].first>=cnt){
//cout<<"flag1"<<endl;
idx--;
}
while(ask[idx].first<cnt){
//cout<<"flag2"<<endl;
idx++;
}
ans[j+1-k][idx]++;
ans[i+j+1-k][idx]++;
//cout<<j+1-k<<' '<<i+j+1-k<<' '<<cnt<<endl;
}
}
for(int i=0;i<n;i++){
for(int j=1;j<=q;j++){
ans[i][j]+=ans[i][j-1];
}
}
vector<int> ans1(q+2);
for(int i=1;i<=q;i++){
int now=0;
for(int j=1;j<=q;j++){
if(ask[j].second==i){
now=j;
break;
}
}
for(int j=0;j<n-k+1;j++){
cout<<ans[j][now]<<' ';
}
cout<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
604 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 |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
604 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 |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
604 KB |
Output is correct |
14 |
Correct |
8 ms |
856 KB |
Output is correct |
15 |
Correct |
7 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
728 KB |
Output is correct |
17 |
Correct |
12 ms |
860 KB |
Output is correct |
18 |
Correct |
11 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
1004 KB |
Output is correct |
2 |
Correct |
250 ms |
1004 KB |
Output is correct |
3 |
Correct |
240 ms |
1004 KB |
Output is correct |
4 |
Correct |
235 ms |
1272 KB |
Output is correct |
5 |
Correct |
156 ms |
1084 KB |
Output is correct |
6 |
Correct |
230 ms |
1216 KB |
Output is correct |
7 |
Correct |
138 ms |
1080 KB |
Output is correct |
8 |
Correct |
157 ms |
1084 KB |
Output is correct |
9 |
Correct |
236 ms |
1488 KB |
Output is correct |
10 |
Correct |
239 ms |
3508 KB |
Output is correct |
11 |
Correct |
13 ms |
604 KB |
Output is correct |
12 |
Correct |
140 ms |
1036 KB |
Output is correct |
13 |
Correct |
175 ms |
1540 KB |
Output is correct |
14 |
Correct |
168 ms |
1080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
1004 KB |
Output is correct |
2 |
Correct |
250 ms |
1004 KB |
Output is correct |
3 |
Correct |
240 ms |
1004 KB |
Output is correct |
4 |
Correct |
235 ms |
1272 KB |
Output is correct |
5 |
Correct |
156 ms |
1084 KB |
Output is correct |
6 |
Correct |
230 ms |
1216 KB |
Output is correct |
7 |
Correct |
138 ms |
1080 KB |
Output is correct |
8 |
Correct |
157 ms |
1084 KB |
Output is correct |
9 |
Correct |
236 ms |
1488 KB |
Output is correct |
10 |
Correct |
239 ms |
3508 KB |
Output is correct |
11 |
Correct |
13 ms |
604 KB |
Output is correct |
12 |
Correct |
140 ms |
1036 KB |
Output is correct |
13 |
Correct |
175 ms |
1540 KB |
Output is correct |
14 |
Correct |
168 ms |
1080 KB |
Output is correct |
15 |
Correct |
240 ms |
1000 KB |
Output is correct |
16 |
Correct |
227 ms |
1128 KB |
Output is correct |
17 |
Correct |
241 ms |
1084 KB |
Output is correct |
18 |
Correct |
234 ms |
1080 KB |
Output is correct |
19 |
Correct |
238 ms |
1220 KB |
Output is correct |
20 |
Correct |
245 ms |
1080 KB |
Output is correct |
21 |
Correct |
252 ms |
1080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
604 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 |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
16 ms |
604 KB |
Output is correct |
14 |
Correct |
8 ms |
856 KB |
Output is correct |
15 |
Correct |
7 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
728 KB |
Output is correct |
17 |
Correct |
12 ms |
860 KB |
Output is correct |
18 |
Correct |
11 ms |
856 KB |
Output is correct |
19 |
Correct |
315 ms |
1004 KB |
Output is correct |
20 |
Correct |
250 ms |
1004 KB |
Output is correct |
21 |
Correct |
240 ms |
1004 KB |
Output is correct |
22 |
Correct |
235 ms |
1272 KB |
Output is correct |
23 |
Correct |
156 ms |
1084 KB |
Output is correct |
24 |
Correct |
230 ms |
1216 KB |
Output is correct |
25 |
Correct |
138 ms |
1080 KB |
Output is correct |
26 |
Correct |
157 ms |
1084 KB |
Output is correct |
27 |
Correct |
236 ms |
1488 KB |
Output is correct |
28 |
Correct |
239 ms |
3508 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
140 ms |
1036 KB |
Output is correct |
31 |
Correct |
175 ms |
1540 KB |
Output is correct |
32 |
Correct |
168 ms |
1080 KB |
Output is correct |
33 |
Correct |
240 ms |
1000 KB |
Output is correct |
34 |
Correct |
227 ms |
1128 KB |
Output is correct |
35 |
Correct |
241 ms |
1084 KB |
Output is correct |
36 |
Correct |
234 ms |
1080 KB |
Output is correct |
37 |
Correct |
238 ms |
1220 KB |
Output is correct |
38 |
Correct |
245 ms |
1080 KB |
Output is correct |
39 |
Correct |
252 ms |
1080 KB |
Output is correct |
40 |
Correct |
359 ms |
3148 KB |
Output is correct |
41 |
Correct |
126 ms |
2560 KB |
Output is correct |
42 |
Correct |
314 ms |
2960 KB |
Output is correct |
43 |
Correct |
285 ms |
2840 KB |
Output is correct |
44 |
Correct |
285 ms |
3096 KB |
Output is correct |
45 |
Correct |
550 ms |
12248 KB |
Output is correct |
46 |
Correct |
129 ms |
8836 KB |
Output is correct |
47 |
Correct |
375 ms |
12484 KB |
Output is correct |
48 |
Correct |
348 ms |
10604 KB |
Output is correct |
49 |
Correct |
337 ms |
11356 KB |
Output is correct |