Submission #943502

# Submission time Handle Problem Language Result Execution time Memory
943502 2024-03-11T14:28:36 Z Aiperiii Lottery (CEOI18_lot) C++14
100 / 100
1609 ms 12560 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n,l,q;
    cin>>n>>l;
    vector <int> a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    cin>>q;
    vector <int> k(q),v;
    for(int i=0;i<q;i++){
        cin>>k[i];
        v.pb(k[i]);
    }
    sort(all(v));
    vector <vector <int> > ans(n+1,vector <int> (q));
    for(int i=1;i<=n;i++){
        if(i+l-1<=n){
            int res=0;
            int ind=1;
            for(int j=i;j<i+l;j++){
                res+=(a[ind]!=a[j]);
                ind++;
            }
            auto it=lower_bound(all(v),res);
            if(it!=v.end())ans[1][it-v.begin()]++;
            int x=2,y=i+1;
            while(x<=n && y<=n && x+l-1<=n && y+l-1<=n){
                int new_res=res-(a[x-1]!=a[y-1])+(a[x+l-1]!=a[y+l-1]);
                res=new_res;
                auto it=lower_bound(all(v),res);
                if(it!=v.end())ans[x][it-v.begin()]++;
                x++;
                y++;
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(i+l-1<=n){
            int res=0;
            int ind=1;
            for(int j=i;j<i+l;j++){
                res+=(a[ind]!=a[j]);
                ind++;
            }
            auto it=lower_bound(all(v),res);
            if(it!=v.end())ans[i][it-v.begin()]++;
            int x=i+1,y=2;
            while(x<=n && y<=n && x+l-1<=n && y+l-1<=n){
                int new_res=res-(a[x-1]!=a[y-1])+(a[x+l-1]!=a[y+l-1]);
                res=new_res;
                auto it=lower_bound(all(v),res);
                if(it!=v.end())ans[x][it-v.begin()]++;
                x++;
                y++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<q;j++)ans[i][j]+=ans[i][j-1];
    }
    for(int i=0;i<q;i++){
        auto pos=lower_bound(all(v),k[i])-v.begin();
        for(int j=1;j<=n-l+1;j++){
            cout<<ans[j][pos]-1<<" ";
        }
        cout<<"\n";
    }
}
/*
6 2
1 2 1 3 2 1
2
1
2
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 404 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 404 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 29 ms 580 KB Output is correct
14 Correct 15 ms 856 KB Output is correct
15 Correct 11 ms 680 KB Output is correct
16 Correct 24 ms 848 KB Output is correct
17 Correct 19 ms 860 KB Output is correct
18 Correct 19 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 548 ms 1104 KB Output is correct
2 Correct 437 ms 1056 KB Output is correct
3 Correct 377 ms 1048 KB Output is correct
4 Correct 363 ms 1052 KB Output is correct
5 Correct 139 ms 1048 KB Output is correct
6 Correct 358 ms 1044 KB Output is correct
7 Correct 129 ms 860 KB Output is correct
8 Correct 219 ms 860 KB Output is correct
9 Correct 364 ms 1056 KB Output is correct
10 Correct 359 ms 860 KB Output is correct
11 Correct 18 ms 604 KB Output is correct
12 Correct 202 ms 860 KB Output is correct
13 Correct 171 ms 860 KB Output is correct
14 Correct 163 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 548 ms 1104 KB Output is correct
2 Correct 437 ms 1056 KB Output is correct
3 Correct 377 ms 1048 KB Output is correct
4 Correct 363 ms 1052 KB Output is correct
5 Correct 139 ms 1048 KB Output is correct
6 Correct 358 ms 1044 KB Output is correct
7 Correct 129 ms 860 KB Output is correct
8 Correct 219 ms 860 KB Output is correct
9 Correct 364 ms 1056 KB Output is correct
10 Correct 359 ms 860 KB Output is correct
11 Correct 18 ms 604 KB Output is correct
12 Correct 202 ms 860 KB Output is correct
13 Correct 171 ms 860 KB Output is correct
14 Correct 163 ms 860 KB Output is correct
15 Correct 410 ms 1108 KB Output is correct
16 Correct 320 ms 856 KB Output is correct
17 Correct 383 ms 1048 KB Output is correct
18 Correct 382 ms 1104 KB Output is correct
19 Correct 370 ms 1048 KB Output is correct
20 Correct 372 ms 1048 KB Output is correct
21 Correct 388 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 404 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 29 ms 580 KB Output is correct
14 Correct 15 ms 856 KB Output is correct
15 Correct 11 ms 680 KB Output is correct
16 Correct 24 ms 848 KB Output is correct
17 Correct 19 ms 860 KB Output is correct
18 Correct 19 ms 860 KB Output is correct
19 Correct 548 ms 1104 KB Output is correct
20 Correct 437 ms 1056 KB Output is correct
21 Correct 377 ms 1048 KB Output is correct
22 Correct 363 ms 1052 KB Output is correct
23 Correct 139 ms 1048 KB Output is correct
24 Correct 358 ms 1044 KB Output is correct
25 Correct 129 ms 860 KB Output is correct
26 Correct 219 ms 860 KB Output is correct
27 Correct 364 ms 1056 KB Output is correct
28 Correct 359 ms 860 KB Output is correct
29 Correct 18 ms 604 KB Output is correct
30 Correct 202 ms 860 KB Output is correct
31 Correct 171 ms 860 KB Output is correct
32 Correct 163 ms 860 KB Output is correct
33 Correct 410 ms 1108 KB Output is correct
34 Correct 320 ms 856 KB Output is correct
35 Correct 383 ms 1048 KB Output is correct
36 Correct 382 ms 1104 KB Output is correct
37 Correct 370 ms 1048 KB Output is correct
38 Correct 372 ms 1048 KB Output is correct
39 Correct 388 ms 856 KB Output is correct
40 Correct 912 ms 3236 KB Output is correct
41 Correct 22 ms 2396 KB Output is correct
42 Correct 607 ms 3220 KB Output is correct
43 Correct 534 ms 2900 KB Output is correct
44 Correct 513 ms 2968 KB Output is correct
45 Correct 1609 ms 12560 KB Output is correct
46 Correct 31 ms 9052 KB Output is correct
47 Correct 886 ms 12452 KB Output is correct
48 Correct 701 ms 10836 KB Output is correct
49 Correct 706 ms 11300 KB Output is correct