Submission #97280

#TimeUsernameProblemLanguageResultExecution timeMemory
97280dalgerokLottery (CEOI18_lot)C++14
100 / 100
695 ms8304 KiB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e4 + 5, M = 1e2 + 5;




int n, m, l, a[N], b[N], c[N], pos[N];
int pref[M][N];


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> l;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    cin >> m;
    for(int i = 1; i <= m; i++){
        cin >> b[i];
        c[i] = b[i];
    }
    sort(c + 1, c + m + 1);
    for(int i = 1; i <= m; i++){
        pos[c[i]] = i;
    }
    pos[n + 1] = m + 1;
    for(int i = n; i >= 0; i--){
        if(pos[i] == 0){
            pos[i] = pos[i + 1];
        }
    }
    for(int shift = 1; l + shift <= n; shift++){
        int ans = 0;
        for(int i = 1; i < l; i++){
            if(a[i] != a[i + shift]){
                ans += 1;
            }
        }
        for(int i = 1; i + l - 1 + shift <= n; i++){
            if(i != 1 && a[i - 1] != a[i - 1 + shift]){
                ans -= 1;
            }
            if(a[i + l - 1] != a[i + l - 1 + shift]){
                ans += 1;
            }
            pref[pos[ans]][i] += 1;
            pref[pos[ans]][i + shift] += 1;
        }
    }
    for(int j = 1; j <= n; j++){
        for(int i = 1; i <= m; i++){
            pref[i][j] += pref[i - 1][j];
        }
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j + l - 1 <= n; j++){
            cout << pref[pos[b[i]]][j] << " ";
        }
        cout << "\n";
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...