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 ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define int ll
// #define int short int
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
#define pdd pair<ld,ld>
const int MAX=1e4+10;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
mt19937 rng;
int n,l,q;
int a[MAX];
int c[MAX][105];
int ans[MAX][105];
pii k[MAX];
int r[MAX];
void solve(){
cin>>n>>l;
for(int i=1;i<=n;i++){
cin>>a[i];
}
cin>>q;
for(int i=1;i<=q;i++){
cin>>k[i].F;
k[i].S=i;
}
sort(k+1,k+q+1);
int pos=1;
for(int i=1;i<=l;i++){
while(pos+1<=q&&i>k[pos].F){
pos++;
}
if(pos==q&&i>k[pos].F)r[i]=q+1;
else r[i]=pos;
}
for(int dif=1;dif+l<=n;dif++){
int i=1,j=dif+1;
int cnt=0;
for(int k=0;k<l;k++){
if(a[i+k]!=a[j+k]){
cnt++;
}
}
c[i][r[cnt]]++;c[j][r[cnt]]++;
i+=l;j+=l;
while(j<=n){
if(a[i]!=a[j])cnt++;
if(a[i-l]!=a[j-l])cnt--;
c[i-l+1][r[cnt]]++;c[j-l+1][r[cnt]]++;
i++,j++;
}
}
for(int i=1;i<=q;i++){
for(int j=1;j<=n-l+1;j++){
c[j][i]+=c[j][i-1];
ans[k[i].S][j]=c[j][i];
}
}
for(int i=1;i<=q;i++){
for(int j=1;j<=n-l+1;j++){
cout<<ans[i][j]<<" ";
}
cout<<"\n";
}
}
main(){
// freopen("color.in", "r", stdin);
// freopen("color.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
}
}
Compilation message (stderr)
lot.cpp:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
90 | 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... |