#include <bits/stdc++.h>
using namespace std;
constexpr int N = (int)7e5;
void solve(){
int n,l;
cin >> n >> l;
int a[n+1];
for(int i = 1; i <= n; i++) cin >> a[i];
vector<int> queries;
vector<int> K;
int q;
cin >> q;
for(int i = 0; i < q; i++){
int k;
cin >> k;
queries.push_back(k);
K.push_back(k);
}
sort(K.begin(),K.end());
int pref[n+1];
int cntDiff[n+1][q+1];
memset(cntDiff,0,sizeof cntDiff);
for(int d = 1; d < n; d++){
memset(pref,0,sizeof pref);
for(int i = 1; i + d <= n; i++){
pref[i] = pref[i-1] + (a[i] != a[i+d]);
}
for(int i = 1; i + d <= n - l + 1; i++){
int cnt = pref[i+l-1] - pref[i-1];
int id = lower_bound(K.begin(),K.end(),cnt) - K.begin();
cntDiff[i][id]++;
cntDiff[i+d][id]++;
}
}
int ans[q];
for(int i = 1; i <= n; i++){
for(int j = 1; j < q; j++){
cntDiff[i][j] += cntDiff[i][j-1];
}
}
for(auto& k : queries){
int id = lower_bound(K.begin(),K.end(),k) - K.begin();
for(int i = 1; i <= n-l+1; i++){
cout << cntDiff[i][id] << " ";
}
cout << "\n";
}
return;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int tests = 1;
for(int test = 1; test <= tests; test++){
solve();
}
return 0;
}
/**
* dist(1,2) = (a[1] != a[2]) + (a[2] != a[3]) + (a[3] != a[4]) + ... + (a[l] != a[l+1])
* dist(1,3) = (a[1] != a[3]) + (a[2] != a[4])
*
*
*
**/
Compilation message
lot.cpp: In function 'void solve()':
lot.cpp:44:6: warning: unused variable 'ans' [-Wunused-variable]
44 | int ans[q];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
17 ms |
340 KB |
Output is correct |
14 |
Correct |
12 ms |
456 KB |
Output is correct |
15 |
Correct |
11 ms |
444 KB |
Output is correct |
16 |
Correct |
16 ms |
512 KB |
Output is correct |
17 |
Correct |
15 ms |
596 KB |
Output is correct |
18 |
Correct |
14 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
472 KB |
Output is correct |
2 |
Correct |
274 ms |
496 KB |
Output is correct |
3 |
Correct |
266 ms |
472 KB |
Output is correct |
4 |
Correct |
264 ms |
468 KB |
Output is correct |
5 |
Correct |
163 ms |
468 KB |
Output is correct |
6 |
Correct |
251 ms |
552 KB |
Output is correct |
7 |
Correct |
156 ms |
548 KB |
Output is correct |
8 |
Correct |
187 ms |
588 KB |
Output is correct |
9 |
Correct |
262 ms |
552 KB |
Output is correct |
10 |
Correct |
267 ms |
544 KB |
Output is correct |
11 |
Correct |
17 ms |
340 KB |
Output is correct |
12 |
Correct |
170 ms |
528 KB |
Output is correct |
13 |
Correct |
178 ms |
568 KB |
Output is correct |
14 |
Correct |
176 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
337 ms |
472 KB |
Output is correct |
2 |
Correct |
274 ms |
496 KB |
Output is correct |
3 |
Correct |
266 ms |
472 KB |
Output is correct |
4 |
Correct |
264 ms |
468 KB |
Output is correct |
5 |
Correct |
163 ms |
468 KB |
Output is correct |
6 |
Correct |
251 ms |
552 KB |
Output is correct |
7 |
Correct |
156 ms |
548 KB |
Output is correct |
8 |
Correct |
187 ms |
588 KB |
Output is correct |
9 |
Correct |
262 ms |
552 KB |
Output is correct |
10 |
Correct |
267 ms |
544 KB |
Output is correct |
11 |
Correct |
17 ms |
340 KB |
Output is correct |
12 |
Correct |
170 ms |
528 KB |
Output is correct |
13 |
Correct |
178 ms |
568 KB |
Output is correct |
14 |
Correct |
176 ms |
564 KB |
Output is correct |
15 |
Correct |
251 ms |
480 KB |
Output is correct |
16 |
Correct |
240 ms |
560 KB |
Output is correct |
17 |
Correct |
267 ms |
588 KB |
Output is correct |
18 |
Correct |
266 ms |
548 KB |
Output is correct |
19 |
Correct |
263 ms |
468 KB |
Output is correct |
20 |
Correct |
263 ms |
556 KB |
Output is correct |
21 |
Correct |
269 ms |
552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
17 ms |
340 KB |
Output is correct |
14 |
Correct |
12 ms |
456 KB |
Output is correct |
15 |
Correct |
11 ms |
444 KB |
Output is correct |
16 |
Correct |
16 ms |
512 KB |
Output is correct |
17 |
Correct |
15 ms |
596 KB |
Output is correct |
18 |
Correct |
14 ms |
512 KB |
Output is correct |
19 |
Correct |
337 ms |
472 KB |
Output is correct |
20 |
Correct |
274 ms |
496 KB |
Output is correct |
21 |
Correct |
266 ms |
472 KB |
Output is correct |
22 |
Correct |
264 ms |
468 KB |
Output is correct |
23 |
Correct |
163 ms |
468 KB |
Output is correct |
24 |
Correct |
251 ms |
552 KB |
Output is correct |
25 |
Correct |
156 ms |
548 KB |
Output is correct |
26 |
Correct |
187 ms |
588 KB |
Output is correct |
27 |
Correct |
262 ms |
552 KB |
Output is correct |
28 |
Correct |
267 ms |
544 KB |
Output is correct |
29 |
Correct |
17 ms |
340 KB |
Output is correct |
30 |
Correct |
170 ms |
528 KB |
Output is correct |
31 |
Correct |
178 ms |
568 KB |
Output is correct |
32 |
Correct |
176 ms |
564 KB |
Output is correct |
33 |
Correct |
251 ms |
480 KB |
Output is correct |
34 |
Correct |
240 ms |
560 KB |
Output is correct |
35 |
Correct |
267 ms |
588 KB |
Output is correct |
36 |
Correct |
266 ms |
548 KB |
Output is correct |
37 |
Correct |
263 ms |
468 KB |
Output is correct |
38 |
Correct |
263 ms |
556 KB |
Output is correct |
39 |
Correct |
269 ms |
552 KB |
Output is correct |
40 |
Correct |
485 ms |
1984 KB |
Output is correct |
41 |
Correct |
132 ms |
1300 KB |
Output is correct |
42 |
Correct |
402 ms |
1992 KB |
Output is correct |
43 |
Correct |
373 ms |
1680 KB |
Output is correct |
44 |
Correct |
378 ms |
1804 KB |
Output is correct |
45 |
Correct |
850 ms |
8216 KB |
Output is correct |
46 |
Correct |
139 ms |
4696 KB |
Output is correct |
47 |
Correct |
542 ms |
8328 KB |
Output is correct |
48 |
Correct |
494 ms |
6476 KB |
Output is correct |
49 |
Correct |
503 ms |
7168 KB |
Output is correct |