Submission #571913

#TimeUsernameProblemLanguageResultExecution timeMemory
571913piOOELottery (CEOI18_lot)C++17
100 / 100
636 ms8260 KiB
#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int)size(x))
#define all(x) begin(x), end(x)
#define trace(x) cout << #x << ": " << (x) << endl;

typedef long long ll;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int rand(int l, int r) { return (int) ((ll) rnd() % (r - l + 1)) + l; }

const int N = 10000, Q = 101;
const ll infL = 3e18;

int a[N], n, l, ans[N][Q];

int count(int i, int j) {
    if (i == j) return 0;
    int aans = 0;
    for (int id = 0; id < l; ++id) {
        aans += (a[i + id] != a[j + id]);
    }
    return aans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> l;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int q;
    cin >> q;
    vector<pair<int, int>> k(q);
    vector<int> ord(q);
    for (int i = 0; i < q; ++i) {
        cin >> k[i].first;
        k[i].second = i;
    }
    sort(all(k));
    for (int i = 0; i < q; ++i)
        ord[k[i].second] = i;
    k.emplace_back(N + 2, -1);
    for (int i = n - l - 1; i > -1; --i) {
        int ct = count(i, n - l);
        int pnt = lower_bound(all(k), make_pair(ct, -1)) - begin(k);
        ans[i][pnt] += 1;
        ans[n - l][pnt] += 1;
        for (int j = 1; j <= i; ++j) {
            ct = ct + (a[i - j] != a[n - l - j]) - (a[i - j + l] != a[n - j]);
            while (k[pnt].first < ct)
                ++pnt;
            while (pnt && k[pnt - 1].first >= ct)
                --pnt;
            ans[i - j][pnt] += 1;
            ans[n - l - j][pnt] += 1;
        }
    }
    for (int i = 0; i <= n - l; ++i) {
        for (int j = 1; j < q; ++j)
            ans[i][j] += ans[i][j - 1];
    }
    for (int i = 0; i < q; ++i) {
        for (int j = 0; j <= n - l; ++j) {
            cout << ans[j][ord[i]] << " ";
        }
        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...