답안 #248572

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
248572 2020-07-12T18:34:34 Z Sprdalo Lottery (CEOI18_lot) C++17
100 / 100
1193 ms 20476 KB
#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

vi t;
vector<vi> sol;

void sredi(int a, int b, int d){
    auto it = lower_bound(t.begin(), t.end(), d);

    if (it == t.end()) return;
    int ind = it - t.begin();

    sol[ind][a]++;
    sol[ind][b]++;
}

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n, x;
    cin >> n >> x;

    vi a(n);
    for (auto& i : a)
        cin >> i;

    int m;
    cin >> m;

    vi q(m);
    set<int> st;
    for (auto& i : q){
        cin >> i;
        st.insert(i);
    }

    for (auto& i : st)
        t.push_back(i);

    int sz = t.size();
    sol = vector<vi>(sz + 2, vi(n + 2, 0));
    vi con(x + 1, 0);
    for (int i = 0; i < sz; ++i){
        con[t[i]] = i;
    }

    for (int dist = 1; dist <= n - x; ++dist){
        int l = 0, r = x - 1, dif = 0;
        for (int i = l; i <= r; ++i){
            dif += (a[i] != a[i + dist]);
        }
        sredi(l, l + dist, dif);

        while(1){
            if (r + dist + 1 >= n) break;
            dif -= (a[l] != a[l + dist]);
            dif += (a[r + 1] != a[r + dist + 1]);
            ++r;
            ++l;
            sredi(l, l + dist, dif);
        }
    }

    vector<vi> p(sz + 2, vi(n + 2, 0));
    for (int i = 0; i < n; ++i){
        p[0][i] = sol[0][i];
        for (int j = 1; j < sz; ++j){
            p[j][i] = p[j - 1][i] + sol[j][i];
        }
    }

    for (int i = 0; i < m; ++i){
        int ind = con[q[i]];

        for (int j = 0; j < n-x+1; ++j){
            cout << p[ind][j] << ' ';
        }

        cout << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 28 ms 632 KB Output is correct
14 Correct 16 ms 1152 KB Output is correct
15 Correct 10 ms 808 KB Output is correct
16 Correct 25 ms 1152 KB Output is correct
17 Correct 25 ms 1152 KB Output is correct
18 Correct 19 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 1144 KB Output is correct
2 Correct 281 ms 1144 KB Output is correct
3 Correct 270 ms 1144 KB Output is correct
4 Correct 263 ms 1128 KB Output is correct
5 Correct 90 ms 1144 KB Output is correct
6 Correct 227 ms 1144 KB Output is correct
7 Correct 131 ms 1144 KB Output is correct
8 Correct 249 ms 1132 KB Output is correct
9 Correct 261 ms 1272 KB Output is correct
10 Correct 260 ms 1124 KB Output is correct
11 Correct 13 ms 512 KB Output is correct
12 Correct 142 ms 1084 KB Output is correct
13 Correct 112 ms 1144 KB Output is correct
14 Correct 115 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 1144 KB Output is correct
2 Correct 281 ms 1144 KB Output is correct
3 Correct 270 ms 1144 KB Output is correct
4 Correct 263 ms 1128 KB Output is correct
5 Correct 90 ms 1144 KB Output is correct
6 Correct 227 ms 1144 KB Output is correct
7 Correct 131 ms 1144 KB Output is correct
8 Correct 249 ms 1132 KB Output is correct
9 Correct 261 ms 1272 KB Output is correct
10 Correct 260 ms 1124 KB Output is correct
11 Correct 13 ms 512 KB Output is correct
12 Correct 142 ms 1084 KB Output is correct
13 Correct 112 ms 1144 KB Output is correct
14 Correct 115 ms 1144 KB Output is correct
15 Correct 378 ms 1184 KB Output is correct
16 Correct 266 ms 1120 KB Output is correct
17 Correct 278 ms 1144 KB Output is correct
18 Correct 273 ms 1136 KB Output is correct
19 Correct 270 ms 1148 KB Output is correct
20 Correct 274 ms 1136 KB Output is correct
21 Correct 262 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 28 ms 632 KB Output is correct
14 Correct 16 ms 1152 KB Output is correct
15 Correct 10 ms 808 KB Output is correct
16 Correct 25 ms 1152 KB Output is correct
17 Correct 25 ms 1152 KB Output is correct
18 Correct 19 ms 1144 KB Output is correct
19 Correct 350 ms 1144 KB Output is correct
20 Correct 281 ms 1144 KB Output is correct
21 Correct 270 ms 1144 KB Output is correct
22 Correct 263 ms 1128 KB Output is correct
23 Correct 90 ms 1144 KB Output is correct
24 Correct 227 ms 1144 KB Output is correct
25 Correct 131 ms 1144 KB Output is correct
26 Correct 249 ms 1132 KB Output is correct
27 Correct 261 ms 1272 KB Output is correct
28 Correct 260 ms 1124 KB Output is correct
29 Correct 13 ms 512 KB Output is correct
30 Correct 142 ms 1084 KB Output is correct
31 Correct 112 ms 1144 KB Output is correct
32 Correct 115 ms 1144 KB Output is correct
33 Correct 378 ms 1184 KB Output is correct
34 Correct 266 ms 1120 KB Output is correct
35 Correct 278 ms 1144 KB Output is correct
36 Correct 273 ms 1136 KB Output is correct
37 Correct 270 ms 1148 KB Output is correct
38 Correct 274 ms 1136 KB Output is correct
39 Correct 262 ms 1132 KB Output is correct
40 Correct 807 ms 4848 KB Output is correct
41 Correct 19 ms 4216 KB Output is correct
42 Correct 610 ms 4856 KB Output is correct
43 Correct 524 ms 4548 KB Output is correct
44 Correct 528 ms 4472 KB Output is correct
45 Correct 1193 ms 20336 KB Output is correct
46 Correct 35 ms 17016 KB Output is correct
47 Correct 986 ms 20476 KB Output is correct
48 Correct 695 ms 16912 KB Output is correct
49 Correct 745 ms 17656 KB Output is correct