#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const ll maxn = 1e4+5;
const ll mod = 998244353;
const ll inf = (1ll<<60);
const int iinf = 1e9+5;
ll pw(ll x, ll p, ll m){
ll ret = 1;
x %= m;
while(p > 0){
if (p & 1){
ret *= x;
ret %= m;
}
x *= x;
x %= m;
p >>= 1;
}
return ret;
}
ll inv(ll x, ll m){
return pw(x, m-2, m);
}
int ans[105][maxn];
signed main(){
IOS();
int n, L; cin>>n>>L;
vector<int> vc(n+1);
REP(i, n) cin>>vc[i];
int q; cin>>q;
vector<int> cores(L+1);
vector<pii> quer;
REP(i, q){
int k; cin>>k;
quer.pb({k, i});
}
sort(ALL(quer));
int ptr = 0;
REP(i, L+1){
while(ptr < SZ(quer) && quer[ptr].f < i){
ptr++;
}
cores[i] = ptr;
}
for (int dif = n-1; dif > -n; dif--){
if (dif == 0) continue;
// j = i+dif
int cnt = 0;
RREP(i, n){
if (i+dif < 0) break;
if (n-i >= L && n-(i+dif) >= L){
cnt += (vc[i] == vc[i+dif]);
cnt -= (vc[i+L] == vc[i+dif+L]); // when it is edge case, one of the extensions will be 0, so ofc not eq
ans[cores[L-cnt]][i]++;
}
else{
if (i+dif < n) cnt += (vc[i] == vc[i+dif]);
}
}
}
vector<int> toads(n);
vector<vector<int>> fans(q);
REP(i, q){
REP(j, n){
toads[j] += ans[i][j];
}
fans[quer[i].s] = toads;
}
REP(i, q){
REP(j, n-L+1) cout<<fans[i][j]<<' ';
cout<<endl;
}
// run from q = 0 ~ L
}
/*
6 2
1 2 1 3 2 1
1
1
*/
# | 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... |