Submission #908662

# Submission time Handle Problem Language Result Execution time Memory
908662 2024-01-16T16:01:17 Z Dec0Dedd Lottery (CEOI18_lot) C++14
100 / 100
1649 ms 8588 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e4+50;
const int Q = 110;

vector<pii> que;
vector<int> q2;
int n, l, q, ans[Q][N], a[N];

void add(int x, int df) {
    int ptr=lower_bound(que.begin(), que.end(), make_pair(df, -1))-que.begin();
    ++ans[ptr][x];
}

bool cmp(pii a, pii b) {
    return a.second < b.second;
}

void solve() {
    cin>>n>>l;
    for (int i=1; i<=n; ++i) cin>>a[i];

    cin>>q;
    for (int i=1; i<=q; ++i) {
        int k; cin>>k;
        que.push_back({k, i});
        q2.push_back(k);
    } sort(que.begin(), que.end());

    for (int d=1; d+l<=n; ++d) {
        // [1, l] and [d+1, d+l]

        int df=0;
        for (int r=0; r<l; ++r) {
            if (a[r+1] != a[d+1+r]) ++df;
        } add(1, df), add(d+1, df);

        //cout<<"FOR "<<1<<" - "<<d+1<<": "<<df<<"\n";
        int j=1;
        while (d+l+j <= n) {
            if (a[j] != a[d+j]) --df;
            if (a[l+j] != a[d+l+j]) ++df;
            add(1+j, df), add(d+1+j, df);
            //cout<<"FOR "<<1+j<<" - "<<d+1+j<<": "<<df<<"\n";
            ++j;
        }
    }

    for (int i=1; i<=q; ++i) {
        for (int j=0; j<N; ++j) ans[i][j]+=ans[i-1][j];
    }

    for (auto u : q2) {
        int x=lower_bound(que.begin(), que.end(), make_pair(u, -1))-que.begin();
        for (int i=1; i+l-1<=n; ++i) cout<<ans[x][i]<<" ";
        cout<<"\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1;
    while (t--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2620 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2512 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2620 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2512 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 27 ms 2640 KB Output is correct
14 Correct 13 ms 2648 KB Output is correct
15 Correct 12 ms 2552 KB Output is correct
16 Correct 24 ms 2576 KB Output is correct
17 Correct 20 ms 2652 KB Output is correct
18 Correct 21 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 704 ms 580 KB Output is correct
2 Correct 806 ms 592 KB Output is correct
3 Correct 446 ms 580 KB Output is correct
4 Correct 399 ms 660 KB Output is correct
5 Correct 117 ms 636 KB Output is correct
6 Correct 346 ms 604 KB Output is correct
7 Correct 148 ms 852 KB Output is correct
8 Correct 247 ms 848 KB Output is correct
9 Correct 393 ms 652 KB Output is correct
10 Correct 374 ms 604 KB Output is correct
11 Correct 22 ms 348 KB Output is correct
12 Correct 226 ms 612 KB Output is correct
13 Correct 165 ms 604 KB Output is correct
14 Correct 175 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 704 ms 580 KB Output is correct
2 Correct 806 ms 592 KB Output is correct
3 Correct 446 ms 580 KB Output is correct
4 Correct 399 ms 660 KB Output is correct
5 Correct 117 ms 636 KB Output is correct
6 Correct 346 ms 604 KB Output is correct
7 Correct 148 ms 852 KB Output is correct
8 Correct 247 ms 848 KB Output is correct
9 Correct 393 ms 652 KB Output is correct
10 Correct 374 ms 604 KB Output is correct
11 Correct 22 ms 348 KB Output is correct
12 Correct 226 ms 612 KB Output is correct
13 Correct 165 ms 604 KB Output is correct
14 Correct 175 ms 600 KB Output is correct
15 Correct 515 ms 604 KB Output is correct
16 Correct 326 ms 900 KB Output is correct
17 Correct 449 ms 760 KB Output is correct
18 Correct 399 ms 908 KB Output is correct
19 Correct 384 ms 856 KB Output is correct
20 Correct 408 ms 656 KB Output is correct
21 Correct 418 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2620 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2388 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2396 KB Output is correct
9 Correct 1 ms 2512 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 27 ms 2640 KB Output is correct
14 Correct 13 ms 2648 KB Output is correct
15 Correct 12 ms 2552 KB Output is correct
16 Correct 24 ms 2576 KB Output is correct
17 Correct 20 ms 2652 KB Output is correct
18 Correct 21 ms 2652 KB Output is correct
19 Correct 704 ms 580 KB Output is correct
20 Correct 806 ms 592 KB Output is correct
21 Correct 446 ms 580 KB Output is correct
22 Correct 399 ms 660 KB Output is correct
23 Correct 117 ms 636 KB Output is correct
24 Correct 346 ms 604 KB Output is correct
25 Correct 148 ms 852 KB Output is correct
26 Correct 247 ms 848 KB Output is correct
27 Correct 393 ms 652 KB Output is correct
28 Correct 374 ms 604 KB Output is correct
29 Correct 22 ms 348 KB Output is correct
30 Correct 226 ms 612 KB Output is correct
31 Correct 165 ms 604 KB Output is correct
32 Correct 175 ms 600 KB Output is correct
33 Correct 515 ms 604 KB Output is correct
34 Correct 326 ms 900 KB Output is correct
35 Correct 449 ms 760 KB Output is correct
36 Correct 399 ms 908 KB Output is correct
37 Correct 384 ms 856 KB Output is correct
38 Correct 408 ms 656 KB Output is correct
39 Correct 418 ms 600 KB Output is correct
40 Correct 1383 ms 3320 KB Output is correct
41 Correct 13 ms 2652 KB Output is correct
42 Correct 671 ms 3720 KB Output is correct
43 Correct 586 ms 3024 KB Output is correct
44 Correct 589 ms 3184 KB Output is correct
45 Correct 1649 ms 8448 KB Output is correct
46 Correct 22 ms 5000 KB Output is correct
47 Correct 918 ms 8588 KB Output is correct
48 Correct 754 ms 6736 KB Output is correct
49 Correct 768 ms 7504 KB Output is correct