답안 #1091080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1091080 2024-09-19T17:15:29 Z TrinhKhanhDung Lottery (CEOI18_lot) C++14
100 / 100
255 ms 8304 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX_N = 1e4 + 10, MAX_Q = 1e2 + 10;

int N, L, Q;
int a[MAX_N];
int ans[MAX_Q][MAX_N], id[MAX_N];
vector<int> queries;

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

    cin >> Q;
    memset(id, -1, sizeof id);
    vector<int> b;
    for(int i = 1; i <= Q; i++){
        int x; cin >> x;
        b.push_back(x);
        queries.push_back(x);
    }

    cps(b);
    for(int i = 0; i < sz(b); i++){
        id[b[i]] = i;
    }

    for(int i = N; i >= 0; i--){
        if(id[i] == -1) id[i] = id[i + 1];
    }

    for(int d = -(N - L); d <= (N - L); d++){
        if(d == 0) continue;
        int cur = 0;
        for(int i = 0; i < L; i++){
            int p = 1 + max(0, d) + i;
            cur += a[p] != a[p - d];
        }
        for(int i = 0; i < N - L + 1 - abs(d); i++){
            int p = 1 + max(d, 0) + i;
            if(id[cur] != -1){
                ans[id[cur]][p]++;
            }
            cur -= a[p] != a[p - d];
            cur += a[p + L] != a[p + L - d];
        }
    }

    for(int i = 1; i < sz(b); i++){
        for(int j = 1; j <= N - L + 1; j++){
            ans[i][j] += ans[i - 1][j];
        }
    }

    for(auto k: queries){
        for(int i = 1; i <= N - L + 1; i++){
            cout << ans[id[k]][i] << ' ';
        }
        cout << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//     freopen("mst.inp","r",stdin);
//     freopen("mst.out","w",stdout);

    int t = 1;
//    cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 8 ms 604 KB Output is correct
14 Correct 6 ms 540 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 9 ms 624 KB Output is correct
17 Correct 7 ms 604 KB Output is correct
18 Correct 6 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 596 KB Output is correct
2 Correct 147 ms 596 KB Output is correct
3 Correct 132 ms 584 KB Output is correct
4 Correct 134 ms 848 KB Output is correct
5 Correct 64 ms 624 KB Output is correct
6 Correct 136 ms 600 KB Output is correct
7 Correct 79 ms 604 KB Output is correct
8 Correct 120 ms 604 KB Output is correct
9 Correct 127 ms 600 KB Output is correct
10 Correct 133 ms 600 KB Output is correct
11 Correct 8 ms 344 KB Output is correct
12 Correct 80 ms 620 KB Output is correct
13 Correct 80 ms 604 KB Output is correct
14 Correct 76 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 596 KB Output is correct
2 Correct 147 ms 596 KB Output is correct
3 Correct 132 ms 584 KB Output is correct
4 Correct 134 ms 848 KB Output is correct
5 Correct 64 ms 624 KB Output is correct
6 Correct 136 ms 600 KB Output is correct
7 Correct 79 ms 604 KB Output is correct
8 Correct 120 ms 604 KB Output is correct
9 Correct 127 ms 600 KB Output is correct
10 Correct 133 ms 600 KB Output is correct
11 Correct 8 ms 344 KB Output is correct
12 Correct 80 ms 620 KB Output is correct
13 Correct 80 ms 604 KB Output is correct
14 Correct 76 ms 600 KB Output is correct
15 Correct 176 ms 576 KB Output is correct
16 Correct 118 ms 644 KB Output is correct
17 Correct 139 ms 604 KB Output is correct
18 Correct 129 ms 600 KB Output is correct
19 Correct 154 ms 600 KB Output is correct
20 Correct 129 ms 668 KB Output is correct
21 Correct 143 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 460 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 8 ms 604 KB Output is correct
14 Correct 6 ms 540 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 9 ms 624 KB Output is correct
17 Correct 7 ms 604 KB Output is correct
18 Correct 6 ms 604 KB Output is correct
19 Correct 255 ms 596 KB Output is correct
20 Correct 147 ms 596 KB Output is correct
21 Correct 132 ms 584 KB Output is correct
22 Correct 134 ms 848 KB Output is correct
23 Correct 64 ms 624 KB Output is correct
24 Correct 136 ms 600 KB Output is correct
25 Correct 79 ms 604 KB Output is correct
26 Correct 120 ms 604 KB Output is correct
27 Correct 127 ms 600 KB Output is correct
28 Correct 133 ms 600 KB Output is correct
29 Correct 8 ms 344 KB Output is correct
30 Correct 80 ms 620 KB Output is correct
31 Correct 80 ms 604 KB Output is correct
32 Correct 76 ms 600 KB Output is correct
33 Correct 176 ms 576 KB Output is correct
34 Correct 118 ms 644 KB Output is correct
35 Correct 139 ms 604 KB Output is correct
36 Correct 129 ms 600 KB Output is correct
37 Correct 154 ms 600 KB Output is correct
38 Correct 129 ms 668 KB Output is correct
39 Correct 143 ms 600 KB Output is correct
40 Correct 207 ms 1872 KB Output is correct
41 Correct 17 ms 856 KB Output is correct
42 Correct 146 ms 2100 KB Output is correct
43 Correct 133 ms 1736 KB Output is correct
44 Correct 134 ms 1620 KB Output is correct
45 Correct 255 ms 8096 KB Output is correct
46 Correct 18 ms 1628 KB Output is correct
47 Correct 244 ms 8304 KB Output is correct
48 Correct 165 ms 5972 KB Output is correct
49 Correct 174 ms 6732 KB Output is correct