Submission #1033207

# Submission time Handle Problem Language Result Execution time Memory
1033207 2024-07-24T14:15:45 Z warrenn Lottery (CEOI18_lot) C++14
0 / 100
106 ms 580 KB
#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+1]!=a[r+1]){
                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
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -