#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);
for (int& i : ask) cin >> i;
vector<int> rev(n+1, -1);
{
int k = 0;
for (int i : ask) {
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 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
4344 KB |
Output is correct |
2 |
Correct |
186 ms |
4348 KB |
Output is correct |
3 |
Correct |
196 ms |
4348 KB |
Output is correct |
4 |
Correct |
292 ms |
4352 KB |
Output is correct |
5 |
Correct |
59 ms |
4308 KB |
Output is correct |
6 |
Correct |
205 ms |
4344 KB |
Output is correct |
7 |
Correct |
74 ms |
4344 KB |
Output is correct |
8 |
Correct |
120 ms |
4308 KB |
Output is correct |
9 |
Correct |
225 ms |
4348 KB |
Output is correct |
10 |
Correct |
192 ms |
4348 KB |
Output is correct |
11 |
Correct |
9 ms |
1492 KB |
Output is correct |
12 |
Correct |
95 ms |
3940 KB |
Output is correct |
13 |
Correct |
100 ms |
4348 KB |
Output is correct |
14 |
Correct |
76 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
4344 KB |
Output is correct |
2 |
Correct |
186 ms |
4348 KB |
Output is correct |
3 |
Correct |
196 ms |
4348 KB |
Output is correct |
4 |
Correct |
292 ms |
4352 KB |
Output is correct |
5 |
Correct |
59 ms |
4308 KB |
Output is correct |
6 |
Correct |
205 ms |
4344 KB |
Output is correct |
7 |
Correct |
74 ms |
4344 KB |
Output is correct |
8 |
Correct |
120 ms |
4308 KB |
Output is correct |
9 |
Correct |
225 ms |
4348 KB |
Output is correct |
10 |
Correct |
192 ms |
4348 KB |
Output is correct |
11 |
Correct |
9 ms |
1492 KB |
Output is correct |
12 |
Correct |
95 ms |
3940 KB |
Output is correct |
13 |
Correct |
100 ms |
4348 KB |
Output is correct |
14 |
Correct |
76 ms |
4352 KB |
Output is correct |
15 |
Correct |
221 ms |
4348 KB |
Output is correct |
16 |
Correct |
162 ms |
4360 KB |
Output is correct |
17 |
Correct |
190 ms |
4344 KB |
Output is correct |
18 |
Correct |
196 ms |
4352 KB |
Output is correct |
19 |
Correct |
192 ms |
4344 KB |
Output is correct |
20 |
Correct |
198 ms |
4348 KB |
Output is correct |
21 |
Correct |
216 ms |
4344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |