#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
// const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 1e4 + 15;
const int maxQ = 1e2 + 3;
int n, l, diff, arr[maxN], cnt[maxN][maxQ], nxt[maxN], qs[maxQ], tmp[maxQ], pos[maxN];
void solve() {
cin >> n >> l;
for (int i = 1; i <= n; i++)
cin >> arr[i];
int q; cin >> q;
for (int i = 1; i <= q; i++)
cin >> qs[i], tmp[i] = qs[i];
sort(tmp + 1, tmp + q + 1);
tmp[q + 1] = l;
// for (int i = 1; i <= q; i++)
// cout << qs[i] << ' ';
// cout << '\n';
// for (int i = 1; i <= q; i++)
// cout << tmp[i] << ' ';
// cout << '\n';
int cur = 1;
for (int i = 0; i <= l; i++) {
nxt[i] = cur;
while (tmp[cur] == i) ++cur;
// cout << i << ' ' << nxt[i] << '\n';
}
for (int i = 2; i + l - 1 <= n; i++) {
diff = 0;
for (int j = i; j <= i + l - 1; j++)
diff += (arr[j - i + 1] != arr[j]);
cnt[1][nxt[diff]]++;
cnt[i][nxt[diff]]++;
// cout << diff << ' ' << nxt[diff] << ' ' << cnt[1][nxt[diff]] << '\n';
// cout << 1 << ' ' << 1 + l - 1 << ' ' << i << ' ' << i + l - 1 << ' ' << diff << '\n';
int j = 1, k = i;
while (k + l <= n) {
diff -= (arr[j] != arr[k]);
diff += (arr[j + l] != arr[k + l]);
j++; k++;
// cout << j << ' ' << j + l - 1 << ' ' << k << ' ' << k + l - 1 << ' ' << diff << '\n';
cnt[j][nxt[diff]]++;
cnt[k][nxt[diff]]++;
}
}
for (int i = 1; i <= q; i++)
pos[tmp[i]] = i;
// for (int j = 1; j <= n - l + 1; j++)
// cout << "!" << cnt[j][pos[28]] << ' ';
// cout << '\n';
for (int i = 1; i <= q; i++)
for (int j = 1; j <= n - l + 1; j++)
cnt[j][i] += cnt[j][i - 1];
// for (int i = 1; i <= q; i++)
// cout << pos[qs[i]] << ' ';
// for (int j = 1; j <= n - l + 1; j++)
// cout << "!" << cnt[j][pos[28]] << ' ';
// cout << '\n';
// cout << nxt[28] << ' ' << pos[28] << '\n';
for (int i = 1; i <= q; i++) {
for (int j = 1; j <= n - l + 1; j++) {
cout << cnt[j][pos[qs[i]]] << ' ';
}
cout << '\n';
}
}
int32_t main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |