#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
int main() {
fast;
int n, l;
cin >> n >> l;
vi a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
int q;
cin >> q;
vector<pii> qs(q);
for (int i = 0; i < q; ++i) {
cin >> qs[i].first;
qs[i].second = i;
}
sort(all(qs));
vi g(n + 1);
for (int i = 0; i <= n; ++i)
g[i] = lower_bound(all(qs), make_pair(i, 0)) - qs.begin();
vector<vi> d(n, vi(q, 0));
for (int k = 1; k < n; ++k) {
vi b(n + 1, 0);
for (int i = 0; i + k < n; ++i) {
int j = i + k;
if (a[i] == a[j])
continue;
++b[max(i - l + 1, 0)];
--b[i - max(j + l - n, 0) + 1];
}
int x = 0;
for (int i = 0; i + k + l <= n; ++i) {
int j = i + k;
x += b[i];
++d[i][g[x]];
++d[j][g[x]];
}
}
vector<vi> ans(q, vi(n - l + 1, 0));
for (int i = 0; i <= n - l; ++i) {
int x = 0;
for (int j = 0; j < q; ++j) {
x += d[i][j];
ans[qs[j].second][i] = x;
}
}
for (int i = 0; i < q; ++i) {
for (int j = 0; j <= n - l; ++j)
cout << ans[i][j] << ' ';
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
1116 KB |
Output is correct |
2 |
Runtime error |
400 ms |
1896 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
396 ms |
1116 KB |
Output is correct |
2 |
Runtime error |
400 ms |
1896 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |