# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
617166 | usuyus | Lottery (CEOI18_lot) | C++14 | 2400 ms | 8228 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;
int main() {
// ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, l; scanf("%d %d", &n, &l);
vector<int> a(n);
for (int &x : a) scanf("%d", &x);
int q; scanf("%d", &q);
vector<int> qs(q);
for (int &x : qs) scanf("%d", &x), x = l-x;
vector<int> qidx(q);
iota(qidx.begin(), qidx.end(), 0);
sort(qidx.begin(), qidx.end(), [&] (int i, int j) {
return qs[i] < qs[j];
});
vector<vector<int>> ans(q, vector<int>(n-l+1));
deque<int> sim(n+1); // offset by l -- sim[i] actually is sim[i-l]
vector<int> cnts(l);
for (int i=-l; i<=n-l; i++) {
sim.pop_back();
sim.push_front(0);
if (0 <= i-1 && i-1 < n)
for (int j=1; j<=n-l; j++)
sim[j+l] -= (a[i-1] == a[j-1]);
if (0 <= i+l-1 && i+l-1 < n)
for (int j=-(l-1); j<n-(l-1); j++)
sim[j+l] += (a[i + (l-1)] == a[j + (l-1)]);
if (i >= 0) {
for (int j=l; j<=n; j++) ++cnts[sim[j]];
int cur = 0, cnt = n-l+1;
for (int j : qidx) {
for (; cur < qs[j]; cur++) cnt -= cnts[cur];
ans[j][i] = cnt - 1;
}
for (int j=l; j<=n; j++) --cnts[sim[j]];
}
}
for (int t=0; t<q; t++) {
for (int i=0; i<=n-l; i++) {
printf("%d ", ans[t][i]);
}
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... |