#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> arr(n);
for (int& i : arr) cin >> i;
int q;
cin >> q;
vector<int> ask(q), asks;
for (int& i : ask) cin >> i;
asks = ask;
sort(asks.begin(), asks.end());
vector<int> rev(n+1, -1);
{
int k = 0;
for (int i : asks) {
rev[i] = k;
k++;
}
}
for (int i = n-1; i >= 0; i--) {
if (rev[i] == -1)
rev[i] = rev[i+1];
if (rev[i] == -1) rev[i] = 100;
}
vector<array<int, 101>> cnt(n, {{}});
for (int b = 1; b + m <= n; b++) {
int al = 0, ar = m-1;
int diff = 0;
int bl = b, br = b + m-1;
for (int i = 0; i < m; i++)
diff += arr[al+i] != arr[bl+i];
// cout << "[" << al << ".." << ar << "] and [" << bl << ".." << br << "] with " << diff << "\n";
cnt[al][rev[diff]]++;
cnt[bl][rev[diff]]++;
while (br < n-1) {
diff -= arr[al++] != arr[bl++];
diff += arr[++ar] != arr[++br];
// cout << "[" << al << ".." << ar << "] and [" << bl << ".." << br << "] with " << diff << "\n";
cnt[al][rev[diff]]++;
cnt[bl][rev[diff]]++;
}
}
for (int i = 0; i < n; i++) {
for (int j = 1; j <= 100; j++)
cnt[i][j] += cnt[i][j-1];
}
for (int k : ask) {
for (int i = 0; i + m <= n; i++) {
cout << cnt[i][rev[k]] << ' ';
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
448 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 |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
448 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
8 ms |
1108 KB |
Output is correct |
14 |
Correct |
6 ms |
1108 KB |
Output is correct |
15 |
Correct |
5 ms |
1172 KB |
Output is correct |
16 |
Correct |
9 ms |
1168 KB |
Output is correct |
17 |
Correct |
7 ms |
1164 KB |
Output is correct |
18 |
Correct |
11 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
4344 KB |
Output is correct |
2 |
Correct |
218 ms |
4348 KB |
Output is correct |
3 |
Correct |
234 ms |
4352 KB |
Output is correct |
4 |
Correct |
191 ms |
4348 KB |
Output is correct |
5 |
Correct |
59 ms |
4340 KB |
Output is correct |
6 |
Correct |
162 ms |
4344 KB |
Output is correct |
7 |
Correct |
58 ms |
4344 KB |
Output is correct |
8 |
Correct |
122 ms |
4360 KB |
Output is correct |
9 |
Correct |
187 ms |
4428 KB |
Output is correct |
10 |
Correct |
205 ms |
4360 KB |
Output is correct |
11 |
Correct |
9 ms |
1492 KB |
Output is correct |
12 |
Correct |
95 ms |
3944 KB |
Output is correct |
13 |
Correct |
78 ms |
4308 KB |
Output is correct |
14 |
Correct |
81 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
4344 KB |
Output is correct |
2 |
Correct |
218 ms |
4348 KB |
Output is correct |
3 |
Correct |
234 ms |
4352 KB |
Output is correct |
4 |
Correct |
191 ms |
4348 KB |
Output is correct |
5 |
Correct |
59 ms |
4340 KB |
Output is correct |
6 |
Correct |
162 ms |
4344 KB |
Output is correct |
7 |
Correct |
58 ms |
4344 KB |
Output is correct |
8 |
Correct |
122 ms |
4360 KB |
Output is correct |
9 |
Correct |
187 ms |
4428 KB |
Output is correct |
10 |
Correct |
205 ms |
4360 KB |
Output is correct |
11 |
Correct |
9 ms |
1492 KB |
Output is correct |
12 |
Correct |
95 ms |
3944 KB |
Output is correct |
13 |
Correct |
78 ms |
4308 KB |
Output is correct |
14 |
Correct |
81 ms |
4308 KB |
Output is correct |
15 |
Correct |
184 ms |
4344 KB |
Output is correct |
16 |
Correct |
196 ms |
4348 KB |
Output is correct |
17 |
Correct |
188 ms |
4348 KB |
Output is correct |
18 |
Correct |
181 ms |
4364 KB |
Output is correct |
19 |
Correct |
193 ms |
4364 KB |
Output is correct |
20 |
Correct |
187 ms |
4356 KB |
Output is correct |
21 |
Correct |
192 ms |
4360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
448 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
8 ms |
1108 KB |
Output is correct |
14 |
Correct |
6 ms |
1108 KB |
Output is correct |
15 |
Correct |
5 ms |
1172 KB |
Output is correct |
16 |
Correct |
9 ms |
1168 KB |
Output is correct |
17 |
Correct |
7 ms |
1164 KB |
Output is correct |
18 |
Correct |
11 ms |
1112 KB |
Output is correct |
19 |
Correct |
198 ms |
4344 KB |
Output is correct |
20 |
Correct |
218 ms |
4348 KB |
Output is correct |
21 |
Correct |
234 ms |
4352 KB |
Output is correct |
22 |
Correct |
191 ms |
4348 KB |
Output is correct |
23 |
Correct |
59 ms |
4340 KB |
Output is correct |
24 |
Correct |
162 ms |
4344 KB |
Output is correct |
25 |
Correct |
58 ms |
4344 KB |
Output is correct |
26 |
Correct |
122 ms |
4360 KB |
Output is correct |
27 |
Correct |
187 ms |
4428 KB |
Output is correct |
28 |
Correct |
205 ms |
4360 KB |
Output is correct |
29 |
Correct |
9 ms |
1492 KB |
Output is correct |
30 |
Correct |
95 ms |
3944 KB |
Output is correct |
31 |
Correct |
78 ms |
4308 KB |
Output is correct |
32 |
Correct |
81 ms |
4308 KB |
Output is correct |
33 |
Correct |
184 ms |
4344 KB |
Output is correct |
34 |
Correct |
196 ms |
4348 KB |
Output is correct |
35 |
Correct |
188 ms |
4348 KB |
Output is correct |
36 |
Correct |
181 ms |
4364 KB |
Output is correct |
37 |
Correct |
193 ms |
4364 KB |
Output is correct |
38 |
Correct |
187 ms |
4356 KB |
Output is correct |
39 |
Correct |
192 ms |
4360 KB |
Output is correct |
40 |
Correct |
201 ms |
5136 KB |
Output is correct |
41 |
Correct |
12 ms |
4468 KB |
Output is correct |
42 |
Correct |
200 ms |
5152 KB |
Output is correct |
43 |
Correct |
184 ms |
4808 KB |
Output is correct |
44 |
Correct |
183 ms |
4984 KB |
Output is correct |
45 |
Correct |
241 ms |
8132 KB |
Output is correct |
46 |
Correct |
16 ms |
4724 KB |
Output is correct |
47 |
Correct |
263 ms |
8272 KB |
Output is correct |
48 |
Correct |
215 ms |
6500 KB |
Output is correct |
49 |
Correct |
226 ms |
7140 KB |
Output is correct |