Submission #246209

#TimeUsernameProblemLanguageResultExecution timeMemory
246209tonowakLottery (CEOI18_lot)C++14
0 / 100
293 ms760 KiB
#include <bits/stdc++.h> // Tomasz Nowak using namespace std; // XIII LO Szczecin using LL = long long; // Poland #define FOR(i, l, r) for(int i = (l); i <= (r); ++i) #define REP(i, n) FOR(i, 0, (n) - 1) template<class T> int size(T &&x) { return int(x.size()); } template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) { out << '{'; for(auto it = x.begin(); it != x.end(); ++it) out << *it << (it == prev(x.end()) ? "" : ", "); return out << '}'; } void dump() {} template<class T, class... Args> void dump(T &&x, Args... args) { cerr << x << "; "; dump(args...); } #ifdef DEBUG struct Nl{~Nl(){cerr << '\n';}}; # define debug(x...) cerr << (strcmp(#x, "") ? #x ": " : ""), dump(x), Nl(), cerr << "" #else # define debug(...) 0 && cerr #endif mt19937_64 rng(0); int rd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } // end of templates int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, l; cin >> n >> l; vector<int> a(n); for(int &ai : a) cin >> ai; int q; cin >> q; vector<int> k(q); for(int &ki : k) cin >> ki; vector<vector<int>> answer(q, vector<int>(n - l + 1)); vector<int> closest_qi(l + 1, -1); REP(i, q) closest_qi[k[i]] = i; for(int i = l - 1; i >= 0; --i) if(closest_qi[i] == -1) closest_qi[i] = closest_qi[i + 1]; debug(k, closest_qi); auto register_diff = [&](int i, int j, int diff) { debug(i, j, diff); if(closest_qi[diff] == -1) return; ++answer[closest_qi[diff]][i]; ++answer[closest_qi[diff]][j]; }; for(int delta = 1; delta + l - 1 < n; ++delta) { int diff = 0; REP(i, l) diff += bool(a[i] != a[i + delta]); register_diff(0, delta, diff); for(int left = 1; left + delta + l - 1 < n; ++left) { int right = left + delta; diff -= bool(a[left - 1] != a[right - 1]); diff += bool(a[left + l - 1] != a[right + l - 1]); register_diff(left, right, diff); } } debug(answer); for(int x = 1; x <= l; ++x) if(closest_qi[x] != closest_qi[x - 1] and closest_qi[x - 1] != -1) REP(i, n - l + 1) answer[closest_qi[x]][i] += answer[closest_qi[x - 1]][i]; REP(i, q) if(closest_qi[k[i]] != i) answer[i] = answer[closest_qi[k[i]]]; REP(i, q) { for(int ans : answer[i]) cout << ans << ' '; cout << '\n'; } }
#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...