Submission #1153547

#TimeUsernameProblemLanguageResultExecution timeMemory
1153547antonnLottery (CEOI18_lot)C++20
100 / 100
471 ms8528 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e4 + 7;
const int Q = 1e2 + 7;

int n, l, q, a[2 * N], cnt[N];
int dist[N], sol[Q][N];
vector<int> qs[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    cin >> q;
    for (int i = 1; i <= q; ++i) {
        int k;
        cin >> k;
        qs[k].push_back(i);
    }
    for (int i = 1; i <= n + 1; ++i) {
        for (int j = 1; j <= l; ++j) {
            dist[i] += (a[i + j - 1] != a[(n - l + 1) + j - 1]);
        }
    }
    
    for (int i = n - l + 1; i >= 1; --i) {
        if (i != n - l + 1) {
            for (int j = 1; j <= n; ++j) {
                dist[j] = dist[j+1] + (a[i] != a[j]) - (a[i+l] != a[j+l]);
            }
        }
        for (int j = 0; j <= l; ++j) {
            cnt[j] = 0;
        }
        for (int j = 1; j <= n - l + 1; ++j) {
            ++cnt[dist[j]];
        }
        for (int j = 1; j <= l; ++j) {
            cnt[j] += cnt[j - 1];
        }
        for (int j = 0; j <= l; ++j) {
            for (auto x : qs[j]) {
                sol[x][i] = cnt[j] - 1;
            }
        }
    }
    for (int i = 1; i <= q; ++i) {
        for (int j = 1; j <= n - l + 1; ++j) {
            cout << sol[i][j] << " ";
        }
        cout << "\n";
    }
    return 0;
}
#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...