Submission #1291562

#TimeUsernameProblemLanguageResultExecution timeMemory
1291562thaibeo123Lottery (CEOI18_lot)C++20
100 / 100
206 ms8384 KiB
#include <bits/stdc++.h>
using namespace std;

#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)

const int N = 1e4 + 5;

int n, l, q;
int a[N], ans[N][105], que[N], b[N], nxt[N];

void input() {
    cin >> n >> l;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    cin >> q;
    for (int i = 1; i <= q; i++) {
        cin >> que[i];
        b[i] = que[i];
    }
    sort(b + 1, b + 1 + q);
    b[q + 1] = l;
    int j = 0;
    for (int i = 1; i <= q + 1; i++) {
        while (j <= b[i]) {
            nxt[j] = i;
            j++;
        }
    }
}

void solve() {
    for (int j = 2; j <= n - l + 1; j++) {
        int diff = 0;
        for (int k = j; k < j + l; k++) {
            diff += (a[k - j + 1] != a[k]);
        }
        int i = 1;
        int jj = j;
        while (jj <= n - l + 1) {
            ans[i][nxt[diff]]++;
            ans[jj][nxt[diff]]++;
            diff = diff - (a[i] != a[jj]) + (a[i + l] != a[jj + l]);
            i++, jj++;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= q; j++) {
            ans[i][j] += ans[i][j - 1];
        }
    }
    for (int i = 1; i <= q; i++) {
        for (int j = 1; j <= n - l + 1; j++) {
            cout << ans[j][nxt[que[i]]] << " ";
        }
        cout << "\n";
    }
}

signed main() {
    if (fopen(NAME".INP", "r")) {
        freopen(NAME".INP", "r", stdin);
        freopen(NAME".OUT", "w", stdout);
    }
    cin.tie(0)->sync_with_stdio(0);

    int t = 1;
    //cin >> t;
    while (t--) {
        input();
        solve();
    }

    return 0;
}

Compilation message (stderr)

lot.cpp: In function 'int main()':
lot.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |         freopen(NAME".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lot.cpp:70:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         freopen(NAME".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...