Submission #530339

#TimeUsernameProblemLanguageResultExecution timeMemory
530339abc864197532Lottery (CEOI18_lot)C++17
100 / 100
1844 ms8356 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define X first #define Y second #define pii pair<int,int> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x); #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0); #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 200000; int main () { owo; int n, len; cin >> n >> len; vector <int> v(n); for (int i = 0; i < n; ++i) cin >> v[i]; int q; cin >> q; vector <int> queries(q); vector <vector <int>> ans(q, vector <int>(n - len + 1)); for (int i = 0; i < q; ++i) cin >> queries[i]; vector <int> id(q); iota(all(id), 0), sort(all(id), [&](int i, int j) { return queries[i] < queries[j]; }); vector <int> res; for (int d = 1; len + d <= n; ++d) { res.assign(n + 1, 0); int bound = max(n - d - len + 1, 0); for (int a = 0; a + d <= n; ++a) { int b = a + d; if (v[a] != v[b]) continue; // x + i = a, y + i = b, a - len < st <= a // y - x = b - a // a - len + 1 <= st < a + 1 res[max(a - len + 1, 0)]++; res[min(a + 1, bound)]--; } vector <int> cnt(n + 1, 0), ord(n - d - len + 1); for (int i = 1; i + d + len <= n; ++i) res[i] += res[i - 1]; for (int i = 0; i + d + len <= n; ++i) cnt[res[i]]++; for (int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1]; for (int i = 0; i + d + len <= n; ++i) { ord[--cnt[res[i]]] = i; } for (int i = n - d - len, j = 0; j < q; ++j) { while (~i && res[ord[i]] >= len - queries[id[j]]) ans[id[j]][ord[i]]++, ans[id[j]][ord[i] + d]++, i--; } } for (int i = 1; i < q; ++i) { for (int j = 0; j + len <= n; ++j) ans[id[i]][j] += ans[id[i - 1]][j]; } for (int i = 0; i < q; ++i) printv(all(ans[i])); }
#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...