Submission #849580

#TimeUsernameProblemLanguageResultExecution timeMemory
849580NeroZeinLottery (CEOI18_lot)C++17
0 / 100
365 ms600 KiB
#include "bits/stdc++.h" using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, l; cin >> n >> l; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int q; cin >> q; vector<pair<int, int>> qs(q); for (int i = 0; i < q; ++i) { cin >> qs[i].first; qs[i].second = i; } sort(qs.begin(), qs.end()); vector<int> nx(l + 1); int p = 0; for (int i = 0; i <= l; ++i) { while (p < q && qs[p].first < i) { p++; } nx[l] = p; } vector<vector<int>> ans(q, vector<int>(n)); auto inc = [&](int x, int y, int mis) { if (nx[mis] < q) { ans[nx[mis]][x]++; ans[nx[mis]][y]++; } }; for (int shift = 1; shift <= n - l; ++shift) { int mis = 0; for (int i = 0; i < l; ++i) { if (a[i] != a[shift + i]) { mis++; } } inc(0, shift, mis); for (int i = 1; i + shift + l <= n; ++i) { if (a[i - 1] != a[i + shift - 1]) { mis--; } if (a[i + l - 1] != a[i + shift + l - 1]) { mis++; } inc(i, i + shift, mis); } } for (int i = 0; i < n; ++i) { for (int j = 1; j < q; ++j) { ans[j][i] += ans[j - 1][i]; } } vector<vector<int>> out(q); for (int i = 0; i < q; ++i) { out[qs[i].second] = ans[i]; } for (int i = 0; i < q; ++i) { for (int j = 0; j < n - l + 1; ++j) { cout << out[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...