# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259924 | pedroslrey | Lottery (CEOI18_lot) | C++17 | 1688 ms | 8512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 10;
const int MAXQ = 1e2 + 10;
int xs[MAXN];
int ans[MAXQ][MAXN];
int rev[MAXQ];
vector<pair<int, int>> queries;
void calc(int n, int l) {
for (int space = 1; space + l - 1 < n; ++space) {
int diffs = 0;
for (int i = 0; i < l; ++i)
if (xs[i] != xs[i + space])
++diffs;
int idx = lower_bound(queries.begin(), queries.end(), make_pair(diffs, 0)) - queries.begin();
++ans[idx][0];
++ans[idx][space];
for (int i = 1; i + space + l - 1 < n; ++i) {
if (xs[i-1] != xs[i + space - 1])
--diffs;
if (xs[i + l - 1] != xs[i + l + space - 1])
++diffs;
int idx = lower_bound(queries.begin(), queries.end(), make_pair(diffs, 0)) - queries.begin();
++ans[idx][i];
++ans[idx][i + space];
}
}
}
int main() {
int n, l;
scanf("%d%d", &n, &l);
for (int i = 0; i < n; ++i)
scanf("%d", &xs[i]);
int q;
scanf("%d", &q);
for (int i = 0; i < q; ++i) {
int k;
scanf("%d", &k);
queries.push_back({k, i});
}
sort(queries.begin(), queries.end());
calc(n, l);
for (int i = 0; i < q; ++i)
rev[queries[i].second] = i;
for (int i = 1; i < q; ++i)
for (int j = 0; j < n - l + 1; ++j)
ans[i][j] += ans[i-1][j];
for (int i = 0; i < q; ++i) {
for (int j = 0; j < n - l + 1; ++j)
printf("%d ", ans[rev[i]][j]);
printf("\n");
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |