This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int short
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
vector <int> ft;
int n, k, q;
int32_t A[10005];
void solve(){
cin >> n >> k;
ft.resize(n+1);
int pref[n-k+2][k+1] = {0};
for(int i=1;i<=n;i++){
cin >> A[i];
}
for(int i=1;i<=n;i++){
for(auto &j : ft)j = 0;
for(int j=1;j<=n-i;j++){
if(A[j] != A[i+j])continue;
int a = j, b = i + j;
int lb = 1 + max(0, b - (n - k + 1));
int ub = min(a, k);
//cerr << i << ' ' << j[a] << ' ' << j[b] << ' ' << j[b] - j[a] << ' ' << lb << ' ' << ub << ' ' << ft[j[b]-j[a]].size() << '\n';
if(lb > ub)continue;
ft[a-ub+1]++;
ft[a-lb+2]--;
}
for(int j=1;j<=n-k-i+1;j++){
ft[j] += ft[j-1];
//cout << ft[j] << ' ';
pref[j][k-ft[j]]++;
pref[j+i][k-ft[j]]++;
}
//cout << '\n';
}
for(int i=1;i<n-k+2;i++){
for(int j=1;j<=k;j++)pref[i][j] += pref[i][j-1];
//for(int j=0;j<=k;j++)cerr << pref[i][j] << ' ';
//cerr << '\n';
}
cin >> q;
while(q--){
int x; cin >> x;
for(int i=1;i<=n-k+1;i++)cout << pref[i][x] << ' ';
cout << '\n';
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
lot.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
60 | main(){
| ^~~~
# | 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... |