Submission #772335

# Submission time Handle Problem Language Result Execution time Memory
772335 2023-07-04T04:04:25 Z treewave Lottery (CEOI18_lot) C++17
100 / 100
346 ms 12836 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, l; cin >> n >> l;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    vector<pair<int,int>> queries_with_idx;
    for (int i = 0; i < q; i++){
        int k; cin >> k;
        queries_with_idx.emplace_back(k, i);
    }
    sort(queries_with_idx.begin(), queries_with_idx.end());
    vector<int> queries, idx_to_real;
    for (int i = 0; i < q; i++){
        queries.push_back(queries_with_idx[i].first);
        idx_to_real.push_back(queries_with_idx[i].second);
    }
    //precompute first greater so no std::lower_bound
    int query_threshold = queries.back()+1;
    vector<int> first_greater(query_threshold);
    for (int i = 0; i < query_threshold; i++){
        first_greater[i] = lower_bound(queries.begin(), queries.end(), i) - queries.begin();
    }
    vector<vector<int>> pref(n-l+1, vector<int> (q, 0));
    for (int offset = 1; offset < n; offset++){
        //out of bounds
        if (l-1 + offset >= n){
            break;
        }
        //initialize
        int last = 0;
        for (int i = 0; i < l; i++){
            last += (a[i] != a[i + offset]);
        }
        int idx;
        if (last < query_threshold){
            idx = first_greater[last];
            pref[0][idx]++;
            pref[offset][idx]++;
        }
        for (int j = 1; j+l-1+offset < n; j++){
            last -= (a[j-1] != a[j-1+offset]);
            last += (a[j+l-1] != a[j+l-1+offset]);
            if (last < query_threshold){
                idx = first_greater[last];
                pref[j][idx]++;
                pref[j+offset][idx]++;
            }
        }
    }
    for (int i = 0; i < n-l+1; i++){
        for (int j = 1; j < q; j++){
            pref[i][j] += pref[i][j-1];
        }
    }
    vector<vector<int>> ans(n-l+1, vector<int>(q, 0));
    for (int i = 0; i < n-l+1; i++){
        for (int j = 0; j < q; j++){
            ans[i][idx_to_real[j]] = pref[i][j];
        }
    }
    for (int i = 0; i < q; i++){
        for (int j = 0; j < n-l+1; j++){
            cout << ans[j][i] << " ";
        }
        cout << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 9 ms 572 KB Output is correct
14 Correct 6 ms 724 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 5 ms 716 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 1508 KB Output is correct
2 Correct 86 ms 1436 KB Output is correct
3 Correct 74 ms 1440 KB Output is correct
4 Correct 71 ms 1504 KB Output is correct
5 Correct 35 ms 976 KB Output is correct
6 Correct 67 ms 1472 KB Output is correct
7 Correct 70 ms 968 KB Output is correct
8 Correct 119 ms 1236 KB Output is correct
9 Correct 75 ms 1504 KB Output is correct
10 Correct 75 ms 1512 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 44 ms 1084 KB Output is correct
13 Correct 41 ms 1036 KB Output is correct
14 Correct 46 ms 1036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 1508 KB Output is correct
2 Correct 86 ms 1436 KB Output is correct
3 Correct 74 ms 1440 KB Output is correct
4 Correct 71 ms 1504 KB Output is correct
5 Correct 35 ms 976 KB Output is correct
6 Correct 67 ms 1472 KB Output is correct
7 Correct 70 ms 968 KB Output is correct
8 Correct 119 ms 1236 KB Output is correct
9 Correct 75 ms 1504 KB Output is correct
10 Correct 75 ms 1512 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 44 ms 1084 KB Output is correct
13 Correct 41 ms 1036 KB Output is correct
14 Correct 46 ms 1036 KB Output is correct
15 Correct 151 ms 1416 KB Output is correct
16 Correct 65 ms 1460 KB Output is correct
17 Correct 81 ms 1532 KB Output is correct
18 Correct 71 ms 1504 KB Output is correct
19 Correct 72 ms 1504 KB Output is correct
20 Correct 72 ms 1508 KB Output is correct
21 Correct 72 ms 1520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 220 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 9 ms 572 KB Output is correct
14 Correct 6 ms 724 KB Output is correct
15 Correct 3 ms 596 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 5 ms 716 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 152 ms 1508 KB Output is correct
20 Correct 86 ms 1436 KB Output is correct
21 Correct 74 ms 1440 KB Output is correct
22 Correct 71 ms 1504 KB Output is correct
23 Correct 35 ms 976 KB Output is correct
24 Correct 67 ms 1472 KB Output is correct
25 Correct 70 ms 968 KB Output is correct
26 Correct 119 ms 1236 KB Output is correct
27 Correct 75 ms 1504 KB Output is correct
28 Correct 75 ms 1512 KB Output is correct
29 Correct 5 ms 468 KB Output is correct
30 Correct 44 ms 1084 KB Output is correct
31 Correct 41 ms 1036 KB Output is correct
32 Correct 46 ms 1036 KB Output is correct
33 Correct 151 ms 1416 KB Output is correct
34 Correct 65 ms 1460 KB Output is correct
35 Correct 81 ms 1532 KB Output is correct
36 Correct 71 ms 1504 KB Output is correct
37 Correct 72 ms 1504 KB Output is correct
38 Correct 72 ms 1508 KB Output is correct
39 Correct 72 ms 1520 KB Output is correct
40 Correct 242 ms 3456 KB Output is correct
41 Correct 11 ms 672 KB Output is correct
42 Correct 102 ms 3372 KB Output is correct
43 Correct 77 ms 3020 KB Output is correct
44 Correct 79 ms 3112 KB Output is correct
45 Correct 346 ms 12636 KB Output is correct
46 Correct 13 ms 1620 KB Output is correct
47 Correct 301 ms 12836 KB Output is correct
48 Correct 118 ms 10704 KB Output is correct
49 Correct 120 ms 11360 KB Output is correct