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;
typedef long long lint;
typedef pair<int, int> pii;
const int INF = 2e9;
const int MOD = 1e9+7;
const int MAX = 1e4+10;
const lint LNF = 2e18;
/*
i + c = x;
j + c = y;
j = y - c = y - x + i;
for each substring i:
if i<=x<i+l A[x] is same as A[y]: cnt[y-x+i]++;
then, do tmp[y-x]++ for all A[x]=A[y];
then cnt[z+i] = tmp[z];
*/
int n, m, l, q, A[MAX], K[101], ans[101][MAX], tmp[MAX*2], cnt[MAX], sum[MAX];
void upt(int i, int v){
for(int j=1; j<=n; j++) if(A[i]==A[j]) tmp[j-i+10000]+=v;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>l; m=n-l+1;
for(int i=1; i<=n; i++) cin>>A[i];
cin>>q;
for(int i=1; i<=q; i++) cin>>K[i];
for(int i=1, lft=1, rig=0; i<=m; i++){
while(rig<i+l-1){ upt(++rig, 1); }
while(lft<i){ upt(lft++, -1); }
for(int j=1; j<=m; j++) cnt[j] = l-tmp[j-i+10000];
fill(sum, sum+l+1, 0);
for(int j=1; j<=m; j++) if(j!=i) sum[cnt[j]]++;
for(int j=1; j<=l; j++) sum[j]+=sum[j-1];
for(int j=1; j<=q; j++) ans[j][i] = sum[K[j]];
}
for(int i=1; i<=q; i++, cout<<'\n') for(int j=1; j<=m; j++) cout<<ans[i][j]<<' ';
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... |