Submission #602411

#TimeUsernameProblemLanguageResultExecution timeMemory
602411pakhomoveeLottery (CEOI18_lot)C++17
80 / 100
3069 ms1032 KiB
#include <iostream>
#include <cstring>

using namespace std;
const int maxn = 10000;
int a[maxn];
int prv[maxn];
int curr[maxn];
int queries[100];
int answer[100][maxn];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, l;
    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> queries[i];
    }
    for (int i = 0; i < n; ++i) {
        prv[i] = (a[0] != a[i]);
    }
    for (int i = 1; i < l; ++i) {
        for (int j = 1; j < n; ++j) {
            curr[j] = prv[j - 1] + (a[i] != a[j]);
        }
        memcpy(prv, curr, maxn * sizeof(int));
    }
    for (int i = 0; i < q; ++i) {
        for (int j = l - 1; j < n; ++j) {
            if (curr[j] <= queries[i]) {
                ++answer[i][l - 1];
            }
        }
    }
    for (int i = l; i < n; ++i) {
        curr[l - 1] = 0;
        for (int p = 0; p < l; ++p) {
            if (a[i - p] != a[l - p - 1]) ++curr[l - 1];
        }
        for (int j = l; j < n; ++j) {
            curr[j] = prv[j - 1] - (a[i - l] != a[j - l]) + (a[i] != a[j]);
        }
        memcpy(prv, curr, maxn * sizeof(int));
        for (int qid = 0; qid < q; ++qid) {
            for (int j = l - 1; j < n; ++j) {
                if (curr[j] <= queries[qid]) {
                    ++answer[qid][i];
                }
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        for (int j = l - 1; j < n; ++j) {
            cout << answer[i][j] - 1 << ' ';
        }
        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...