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;
int n, l, q, m, A[10010], cnt[101][10010], lim, now[10010], K[101], sum[10010], tmp[20010];
vector<int> X, P[10010];
vector<pair<int, int>> Q;
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], X.push_back(A[i]);
cin>>q; for(int i=1; i<=q; i++) cin>>K[i], Q.push_back({K[i], i});
sort(Q.begin(), Q.end());
sort(X.begin(), X.end());
lim=unique(X.begin(), X.end())-X.begin();
X.resize(lim);
for(int i=1; i<=n; i++) A[i]=lower_bound(X.begin(), X.end(), A[i])-X.begin();
for(int i=1; i<=n; i++) P[A[i]].push_back(i);
for(int i=1, lft=1, rig=0; i<=m; i++){
while(rig+1<i+l){
rig++;
// cout<<"IN: "<<rig<<'\n';
for(int j=1; j<=n; j++)
if(A[j]==A[rig])
tmp[j-rig+10000]++;
}
if(lft<i){
// cout<<"OUT: "<<lft<<'\n';
for(int j=1; j<=n; j++)
if(A[j]==A[lft]) tmp[j-lft+10000]--;
lft++;
}
for(int j=1; j<=n; j++) now[j]=l;
for(int j=0; j<=20000; j++){
int pos=i+j-10000;
if(1<=pos && pos<=m) now[pos]-=tmp[j];
}
/*
for(int j=0; j<lim; j++){
vector<int> Q;
for(int p:P[j]) if(i<=p && p<i+l) Q.push_back(p-i);
if(Q.empty()) continue;
for(int p:P[j]) for(int q:Q) if(1<=p-q && p-q<=m) now[p-q]--;
}
*/
/*
cout<<"SOLVING: "<<i<<": \n";
for(int s=1; s<=m; s++) cout<<now[s]<<' ';
cout<<'\n';
*/
for(int j=0; j<=l; j++) sum[j]=0;
for(int j=1; j<=m; j++) if(j!=i) sum[now[j]]++;
for(int j=1; j<=l; j++) sum[j]+=sum[j-1];
for(int j=0, s=0; j<(int)Q.size(); j++){
int val, idx; tie(val,idx)=Q[j];
while(s<val) s++;
cnt[idx][i]=sum[s];
}
}
for(int i=1; i<=q; i++, cout<<'\n') for(int j=1; j<=m; j++) cout<<cnt[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... |