답안 #415106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
415106 2021-05-31T14:30:31 Z meatrow Lottery (CEOI18_lot) C++17
100 / 100
630 ms 8428 KB
// #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;
        while (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++) {
        int cur = id[queries[i].first];
        for (int j = 0; j <= n - l; j++) {
            cout << ans[j][cur] << " \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

lot.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization ("O3")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 21 ms 1164 KB Output is correct
14 Correct 13 ms 1228 KB Output is correct
15 Correct 12 ms 1160 KB Output is correct
16 Correct 20 ms 1248 KB Output is correct
17 Correct 18 ms 1204 KB Output is correct
18 Correct 18 ms 1172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 4448 KB Output is correct
2 Correct 469 ms 4548 KB Output is correct
3 Correct 488 ms 4444 KB Output is correct
4 Correct 486 ms 4368 KB Output is correct
5 Correct 143 ms 2380 KB Output is correct
6 Correct 423 ms 4172 KB Output is correct
7 Correct 142 ms 2416 KB Output is correct
8 Correct 259 ms 3232 KB Output is correct
9 Correct 452 ms 4420 KB Output is correct
10 Correct 472 ms 4376 KB Output is correct
11 Correct 21 ms 1100 KB Output is correct
12 Correct 245 ms 3208 KB Output is correct
13 Correct 189 ms 2792 KB Output is correct
14 Correct 198 ms 2884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 490 ms 4448 KB Output is correct
2 Correct 469 ms 4548 KB Output is correct
3 Correct 488 ms 4444 KB Output is correct
4 Correct 486 ms 4368 KB Output is correct
5 Correct 143 ms 2380 KB Output is correct
6 Correct 423 ms 4172 KB Output is correct
7 Correct 142 ms 2416 KB Output is correct
8 Correct 259 ms 3232 KB Output is correct
9 Correct 452 ms 4420 KB Output is correct
10 Correct 472 ms 4376 KB Output is correct
11 Correct 21 ms 1100 KB Output is correct
12 Correct 245 ms 3208 KB Output is correct
13 Correct 189 ms 2792 KB Output is correct
14 Correct 198 ms 2884 KB Output is correct
15 Correct 462 ms 4312 KB Output is correct
16 Correct 397 ms 4044 KB Output is correct
17 Correct 484 ms 4460 KB Output is correct
18 Correct 475 ms 4400 KB Output is correct
19 Correct 471 ms 4404 KB Output is correct
20 Correct 478 ms 4408 KB Output is correct
21 Correct 471 ms 4408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 21 ms 1164 KB Output is correct
14 Correct 13 ms 1228 KB Output is correct
15 Correct 12 ms 1160 KB Output is correct
16 Correct 20 ms 1248 KB Output is correct
17 Correct 18 ms 1204 KB Output is correct
18 Correct 18 ms 1172 KB Output is correct
19 Correct 490 ms 4448 KB Output is correct
20 Correct 469 ms 4548 KB Output is correct
21 Correct 488 ms 4444 KB Output is correct
22 Correct 486 ms 4368 KB Output is correct
23 Correct 143 ms 2380 KB Output is correct
24 Correct 423 ms 4172 KB Output is correct
25 Correct 142 ms 2416 KB Output is correct
26 Correct 259 ms 3232 KB Output is correct
27 Correct 452 ms 4420 KB Output is correct
28 Correct 472 ms 4376 KB Output is correct
29 Correct 21 ms 1100 KB Output is correct
30 Correct 245 ms 3208 KB Output is correct
31 Correct 189 ms 2792 KB Output is correct
32 Correct 198 ms 2884 KB Output is correct
33 Correct 462 ms 4312 KB Output is correct
34 Correct 397 ms 4044 KB Output is correct
35 Correct 484 ms 4460 KB Output is correct
36 Correct 475 ms 4400 KB Output is correct
37 Correct 471 ms 4404 KB Output is correct
38 Correct 478 ms 4408 KB Output is correct
39 Correct 471 ms 4408 KB Output is correct
40 Correct 510 ms 5208 KB Output is correct
41 Correct 19 ms 4556 KB Output is correct
42 Correct 517 ms 5276 KB Output is correct
43 Correct 463 ms 4880 KB Output is correct
44 Correct 475 ms 5016 KB Output is correct
45 Correct 630 ms 8428 KB Output is correct
46 Correct 29 ms 4812 KB Output is correct
47 Correct 586 ms 8404 KB Output is correct
48 Correct 554 ms 6552 KB Output is correct
49 Correct 617 ms 7224 KB Output is correct