Submission #415102

#TimeUsernameProblemLanguageResultExecution timeMemory
415102meatrowLottery (CEOI18_lot)C++17
35 / 100
504 ms4556 KiB
// #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MOD = 1e9 + 7; ll binpow(ll a, ll p, int mod = MOD) { ll res = 1; while (p) { if (p & 1) { (res *= a) %= mod; } p >>= 1; (a *= a) %= mod; } return res; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } const int N = 10005; const int Q = 105; int a[N], id[N]; int ans[N][Q]; void solve() { int n, l; cin >> n >> l; for (int i = 0; i < n; i++) { cin >> a[i]; } int q; cin >> q; vector<pair<int, int>> queries(q); for (int i = 0; i < q; i++) { cin >> queries[i].first; queries[i].second = i; } sort(queries.begin(), queries.end()); queries.push_back({1e9, q}); int cur = 0; for (int i = 0; i <= l; i++) { id[i] = cur; if (i == queries[cur].first) { cur++; } } for (int i = 1; i <= n - l; i++) { // [0, i] -> [1, i + 1] int dist = 0; for (int pos = 0; pos < l; pos++) { dist += a[pos] != a[i + pos]; } ans[0][id[dist]]++; ans[i][id[dist]]++; for (int j = i + 1; j <= n - l; j++) { dist += a[l + j - i - 1] != a[l + j - 1]; dist -= a[j - i - 1] != a[j - 1]; ans[j - i][id[dist]]++; ans[j][id[dist]]++; } } for (int i = 0; i < n; i++) { for (int j = 1; j < q; j++) { ans[i][j] += ans[i][j - 1]; } } sort(queries.begin(), queries.end(), [](const auto& f, const auto& s) { return f.second < s.second; }); for (int i = 0; i < q; i++) { for (int j = 0; j <= n - l; j++) { cout << ans[j][i] << " \n"[j == n - l]; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; for (int tc = 1; tc <= T; tc++) { // cout << "Case #" << tc << ": "; solve(); } return 0; }

Compilation message (stderr)

lot.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      |
#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...