QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711936#7949. K-Lotterykizen#WA 1515ms82552kbC++204.2kb2024-11-05 14:02:142024-11-05 14:02:16

Judging History

你现在查看的是最新测评结果

  • [2024-11-05 14:02:16]
  • 评测
  • 测评结果:WA
  • 用时:1515ms
  • 内存:82552kb
  • [2024-11-05 14:02:14]
  • 提交

answer

#include <bits/stdc++.h>

#ifndef LOCAL
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#endif

#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pi array<int, 2>
#define comp(v) (sort(all(v)), v.erase(unique(all(v)), v.end()))
#define lb(v, x) (lower_bound(all(v), x) - v.begin())

using namespace std;

#define int long long

const pi v1 = {103, 1610612741};
// const pi v1 = {97, 805306457};

struct Seg{
    int n;
    vector<int> tr;
    Seg(int m){
        n = m + 4;
        tr.resize(n * 4 + 4);
    }

    void push(int x, int s, int e, int pos, int val){
        if(s == e){
            tr[x] = val;
            return;
        }
        int m = s + e >> 1;
        if(pos <= m) push(x * 2, s, m, pos, val);
        else push(x * 2 + 1, m + 1, e, pos, val);
        tr[x] = (tr[x * 2] + tr[x * 2 + 1]) % v1[1];
    }

    int get(int x, int s, int e, int fs, int fe){
        if(fe < s || fs > e || fs > fe) return 0;
        if(fs <= s && fe >= e) return tr[x];
        int m = s + e >> 1;
        return (get(x * 2, s, m, fs, fe) + get(x * 2 + 1, m + 1, e, fs, fe)) % v1[1];
    }
};


int pw(int x, int y, int md){
    if(!y) return 1;
    if(y == 1) return x % md;
    int v = pw(x, y >> 1, md);
    (v *= v) %= md;
    if(y & 1) (v *= x) %= md;
    return v;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int k, m, n; cin >> k >> m >> n;
    vector<vector<int>> a(m, vector<int>(k));
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < k; ++j){
            cin >> a[i][j]; --a[i][j];
        }
    }
    
    vector<int> hsh(m + 1);
    for(int i = 0; i < m; ++i){
        Seg tr(k + 4);
        for(int j = 0; j < k; ++j){
            int rv = tr.get(1, 0, k - 1, a[i][j], k - 1);
            (rv *= pw(v1[0], j, v1[1])) %= v1[1];
            (hsh[i] += rv) %= v1[1];

            tr.push(1, 0, k - 1, a[i][j], pw(v1[0], j * k, v1[1]));
        }
    }

    vector<int> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
    }
    auto srt = p;
    comp(srt);
    for(int i = 0; i < n; ++i){
        p[i] = lb(srt, p[i]);
    }

    Seg tr(n + 4), rt(n + 4);
    for(int j = 0; j < k; ++j){
        int rv = tr.get(1, 0, n - 1, p[j], n - 1);
        (rv *= pw(v1[0], j, v1[1])) %= v1[1];
        (hsh[m] += rv) %= v1[1];

        tr.push(1, 0, n - 1, p[j], pw(v1[0], j * k, v1[1]));
        rt.push(1, 0, n - 1, p[j], pw(v1[0], j, v1[1]));
    }

    vector<int> id(m);
    iota(all(id), 0);
    sort(all(id), [&](int x, int y){return hsh[x] < hsh[y];});

    int inv1 = pw(v1[0], v1[1] - 2, v1[1]);
    int inv1k1 = pw(inv1, k + 1, v1[1]);
    int inv1k = pw(inv1, k, v1[1]);
    int k1 = pw(v1[0], k - 1, v1[1]);

    int inv1kinv = pw(inv1k, v1[1] - 2, v1[1]);

    // for(int i = 0; i <= m; ++i){
    //     cout << hsh[i] << endl;
    // }

    int trgop = 1, rtgop = 1;
    int trgopinv = 1, rtgopinv = 1;
    for(int i = 0; i + k <= n; ++i){
        int pos = lower_bound(id.begin(), id.end(), m, [&](int x, int y){return hsh[x] < hsh[y];}) - id.begin();
        if(pos < sz(id) && hsh[id[pos]] == hsh[m]){
            for(int j = 0; j < k; ++j){
                cout << a[id[pos]][j] + 1 << ' ';
            }
            return 0;
        }

        if(i + k < n){
            rt.push(1, 0, n - 1, p[i], 0);
            tr.push(1, 0, n - 1, p[i], 0);

            // cout << hsh[m] << ' ';

            (hsh[m] += v1[1] - rt.get(1, 0, n - 1, 0, p[i] - 1) * rtgop % v1[1]) %= v1[1];

            // cout << hsh[m] << ' ';

            (hsh[m] *= inv1k1) %= v1[1];
            (trgop *= inv1k) %= v1[1];
            (rtgop *= inv1) %= v1[1];
            (trgopinv *= inv1kinv) %= v1[1];
            (rtgopinv *= v1[0]) %= v1[1];

            // cout << hsh[m] << ' ';

            int rv = tr.get(1, 0, n - 1, p[i + k], n - 1) * trgop % v1[1];
            (rv *= k1) %= v1[1];
            (hsh[m] += rv) %= v1[1];

            tr.push(1, 0, n - 1, p[i + k], pw(k1, k, v1[1]) * trgopinv % v1[1]);
            rt.push(1, 0, n - 1, p[i + k], k1 * rtgopinv % v1[1]);

            // cout << endl;
        }
    }

    cout << 0;

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

3 2 10
1 2 3
1 3 2
20 35 10 7 99 53 72 33 88 16

output:

1 3 2 

result:

ok single line: '1 3 2 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

4 5 10
1 2 3 4
1 2 4 3
3 4 1 2
4 1 2 3
4 2 3 1
19 31 9 1 89 48 63 30 78 12

output:

4 2 3 1 

result:

ok single line: '4 2 3 1 '

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

3 3 7
1 3 2
2 3 1
2 1 3
11 22 33 44 55 66 77

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 832ms
memory: 82284kb

input:

10000 10 1000000
1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5...

output:

1 5001 2 5002 3 5003 4 5004 5 5005 6 5006 7 5007 8 5008 9 5009 10 5010 11 5011 12 5012 13 5013 14 5014 15 5015 16 5016 17 5017 18 5018 19 5019 20 5020 21 5021 22 5022 23 5023 24 5024 25 5025 26 5026 27 5027 28 5028 29 5029 30 5030 31 5031 32 5032 33 5033 34 5034 35 5035 36 5036 37 5037 38 5038 39 50...

result:

ok single line: '1 5001 2 5002 3 5003 4 5004 5 ...4998 9998 4999 9999 5000 10000 '

Test #5:

score: 0
Accepted
time: 1515ms
memory: 82444kb

input:

10000 10 1000000
7171 4541 8189 3253 6694 2078 7384 1786 7847 5040 953 4126 4806 3532 7875 8531 3543 2706 8565 1509 2092 4125 6110 5251 6314 4574 6726 8900 9328 8639 3990 5234 9012 5023 3289 2825 8038 3593 2249 337 6252 3831 7967 3839 2815 540 3754 1009 8772 2939 2845 5067 6587 2615 375 7252 9940 18...

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 822ms
memory: 82552kb

input:

10000 10 1000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 1459ms
memory: 82480kb

input:

10000 10 1000000
3 7 8 1 4 10 2 5 9 6 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 1470ms
memory: 82536kb

input:

10000 10 1000000
1 3 7 10 6 4 9 8 2 5 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...

output:

0

result:

ok single line: '0'

Test #9:

score: -100
Wrong Answer
time: 1109ms
memory: 82052kb

input:

100 1000 1000000
34 82 39 96 30 85 83 16 8 31 51 63 76 49 3 7 58 17 42 94 41 9 11 47 89 6 86 19 100 77 37 93 40 15 36 71 23 46 48 55 2 92 64 18 22 21 12 72 1 99 70 81 56 57 53 62 50 35 65 43 73 60 97 24 4 98 20 90 26 68 66 25 74 87 14 67 45 95 33 32 52 29 5 88 54 13 91 10 59 80 28 38 78 61 79 75 69 ...

output:

95 4 82 53 65 48 1 47 79 90 68 96 71 38 73 21 97 86 6 93 24 81 72 40 84 100 17 25 87 13 62 28 63 22 8 37 98 99 52 67 64 49 70 60 3 14 42 36 50 54 2 88 89 33 27 51 78 85 5 57 77 55 76 75 16 74 35 32 39 30 61 12 69 34 45 26 43 83 7 41 23 20 9 15 59 58 80 44 18 66 56 11 91 10 29 94 46 19 92 31 

result:

wrong answer 1st lines differ - expected: '0', found: '95 4 82 53 65 48 1 47 79 90 68... 56 11 91 10 29 94 46 19 92 31 '