이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,leng;
cin>>n>>leng;
int a[n+1];
for(int q=1;q<=n;q++){
cin>>a[q];
}
int q;
cin>>q;
pair<int,int>tny[q+1];
for(int w=1;w<=q;w++){
cin>>tny[w].first;
tny[w].second=w;
}
sort(tny+1,tny+q+1);
int pos[leng+1];
memset(pos,-1,sizeof pos);
for(int w=1;w<=q;w++){
if(pos[tny[w].first]==-1){
pos[tny[w].first]=w;
}
}
for(int w=leng-1;w>=0;w--){
if(pos[w]==-1){
pos[w]=pos[w+1];
}
}
int cnt[q+1][n+1];
memset(cnt,0,sizeof cnt);
for(int w=1;w<=n;w++){
int l=1,r=w+1;
int diff=0;
if(r+leng-1>n)break;
for(int j=0;j<leng;j++){
if(a[l+j]!=a[r+j]){
diff++;
}
}
cnt[pos[diff]][l]++;
cnt[pos[diff]][r]++;
while(r+leng<=n){
if(a[l+leng]!=a[r+leng]){
diff++;
}
if(a[l]!=a[r]){
diff--;
}
l++,r++;
cnt[pos[diff]][l]++;
cnt[pos[diff]][r]++;
}
}
for(int w=2;w<=q;w++){
for(int e=1;e<=n;e++){
cnt[w][e]+=cnt[w-1][e];
}
}
int ans[q+1][n+1];
for(int w=1;w<=q;w++){
for(int e=1;e<=n;e++){
ans[tny[w].second][e]=cnt[w][e];
}
}
for(int w=1;w<=q;w++){
for(int e=1;e<=n-leng+1;e++){
cout<<ans[w][e]<<" ";
}
cout<<endl;
}
}
# | 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... |