QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#71782#2864. 切树游戏He_Ren100 ✓283ms167028kbC++146.6kb2023-01-12 01:12:272023-01-12 01:12:30

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-12 01:12:30]
  • 评测
  • 测评结果:100
  • 用时:283ms
  • 内存:167028kb
  • [2023-01-12 01:12:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MAXN = 3e4 + 5;
const int maxm = 128, MAXM = maxm + 5;
const int mod = 10007;
const int inv2 = (mod + 1) / 2;

inline void add_mod(int &a, int b) {
    a += b;

    if (a >= mod)
        a -= mod;
}
inline int mod_add(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}

inline ll pw(ll a, ll b) {
    ll res = 1;

    while (b) {
        if (b & 1)
            res = res * a % mod;

        a = a * a % mod;
        b >>= 1;
    }

    return res;
}

template<typename T>
struct Segment_Tree {
    static const int MAXP = MAXN * 2;
    T val[MAXP];
    int ls[MAXP], rs[MAXP], fa[MAXP], pcnt = 0;

    int build(int l, int r, int leaf[]) {
        if (l > r)
            return 0;

        int u = ++pcnt;
        ls[u] = rs[u] = fa[u] = 0;

        if (l == r) {
            leaf[l] = u;
            return u;
        }

        int mid = (l + r) >> 1;
        ls[u] = build(l, mid, leaf);
        rs[u] = build(mid + 1, r, leaf);
        fa[ls[u]] = fa[rs[u]] = u;
        return u;
    }
    void push_up_all(int u) {
        if (!ls[u])
            return;

        push_up_all(ls[u]);
        push_up_all(rs[u]);
        val[u].merge(val[ls[u]], val[rs[u]]);
    }
    void flush(int u) {
        while ((u = fa[u]) != 0)
            val[u].merge(val[ls[u]], val[rs[u]]);
    }
};

#define lowbit(x) ((x)&-(x))
int parity[MAXM];

int m;

struct Data1;
struct Data2;

struct Data1: array< array<int, 2>, maxm > {
    void set(int k) {
        for (int i = 0; i < m; ++i) {
            data()[i][0] = 0;
            data()[i][1] = parity[i & k] ? mod - 1 : 1;
        }
    }
    void merge(const Data1 &f, const Data1 &g) {
        for (int k = 0; k < m; ++k) {
            data()[k][0] = mod_add(f[k][0], g[k][0]);
            data()[k][1] = f[k][1] * g[k][1] % mod;
        }
    }
    void copy(const Data2 &);
};

struct Data2: array< array<int, 4>, maxm > {
    void merge(const Data2 &f, const Data2 &g) {
        for (int k = 0; k < m; ++k) {
            int *res = data()[k].data();
            const int *F = f.data()[k].data(), *G = g.data()[k].data();

            res[0] = (F[0] + G[0] + (F[1] + 1) * (G[2] + 1) - 1) % mod;
            res[1] = ((F[1] + 1) * G[3] + G[1]) % mod;
            res[2] = ((G[2] + 1) * F[3] + F[2]) % mod;
            res[3] = (F[3] * G[3]) % mod;
        }
    }
    void merge(const Data1 &f, const Data1 &g) {
        for (int k = 0; k < m; ++k) {
            int *res = data()[k].data();
            const int *F = f.data()[k].data(), *G = g.data()[k].data();

            res[0] = mod_add(F[0], G[0]);
            res[1] = res[2] = 0;
            res[3] = F[1] * G[1] % mod;
        }
    }
    void copy(const Data1 &);
};

void Data1::copy(const Data2 &f) {
    for (int k = 0; k < m; ++k) {
        int *res = data()[k].data();
        const int *F = f.data()[k].data();

        res[0] = (F[0] + F[1] + F[2] + F[3]) % mod;
        res[1] = (F[2] + F[3] + 1) % mod;
    }
}
void Data2::copy(const Data1 &f) {
    for (int k = 0; k < m; ++k) {
        int *res = data()[k].data();
        const int *F = f.data()[k].data();

        res[0] = F[0];
        res[1] = res[2] = 0;
        res[3] = F[1];
    }
}

vector<int> g[MAXN];

Data1 val[MAXN];
Segment_Tree<Data1> tree1;
Segment_Tree<Data2> tree2;

int rt1[MAXN], rt2[MAXN], pos1[MAXN], pos2[MAXN];
Data1 *ppos1[MAXN];
Data2 *ppos2[MAXN];

void upd_tree2(int u, bool needflush) {
    if (rt1[u])
        ppos2[u] -> merge(val[u], tree1.val[rt1[u]]);
    else
        ppos2[u] -> copy(val[u]);

    if (needflush)
        tree2.flush(pos2[u]);
}
void upd_tree1(int u, bool needflush) {
    if (pos1[u]) {
        ppos1[u] -> copy(tree2.val[rt2[u]]);

        if (needflush)
            tree1.flush(pos1[u]);
    }
}

int siz[MAXN], son[MAXN], anc[MAXN];
void dfs_tree(int u, int fa) {
    anc[u] = fa;
    siz[u] = 1;
    son[u] = 0;

    for (int v : g[u])
        if (v != fa) {
            dfs_tree(v, u);
            siz[u] += siz[v];

            if (son[u] == 0 || siz[v] > siz[son[u]])
                son[u] = v;
        }
}

int dfn[MAXN], seq[MAXN], top[MAXN], bot[MAXN], curdfn = 0;
void dfs_dfn(int u, int fa, int tp) {
    dfn[u] = ++curdfn;
    seq[curdfn] = u;
    top[u] = tp;
    bot[top[u]] = u;

    if (son[u])
        dfs_dfn(son[u], u, tp);

    vector<int> ch;

    for (int v : g[u])
        if (v != fa && v != son[u]) {
            dfs_dfn(v, u, v);
            ch.emplace_back(v);
        }

    static int leaf[MAXN];
    rt1[u] = tree1.build(0, (int)ch.size() - 1, leaf);

    for (int i = 0; i < (int)ch.size(); ++i) {
        pos1[ch[i]] = leaf[i];
        ppos1[ch[i]] = &tree1.val[leaf[i]];
        upd_tree1(ch[i], 0);
    }

    tree1.push_up_all(rt1[u]);

    if (u == tp) {
        int l = dfn[u], r = dfn[bot[u]];
        rt2[u] = tree2.build(l, r, leaf);

        for (int i = l; i <= r; ++i) {
            pos2[seq[i]] = leaf[i];
            ppos2[seq[i]] = &tree2.val[leaf[i]];
            upd_tree2(seq[i], 0);
        }

        tree2.push_up_all(rt2[u]);
    }
}

int main(void) {
    for (int i = 1; i < MAXM; ++i)
        parity[i] = parity[i ^ lowbit(i)] ^ 1;

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n >> m;

    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        val[i].set(x);
    }

    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }

    dfs_tree(1, 0);
    dfs_dfn(1, 0, 1);

    ll ivm = pw(m, mod - 2);

    int Q;
    cin >> Q;

    while (Q--) {
        static char op[10];
        cin >> op;

        if (*op == 'C') {
            int u, k;
            cin >> u >> k;
            val[u].set(k);

            while (u) {
                upd_tree2(u, 1);
                u = top[u];
                upd_tree1(u, 1);
                u = anc[u];
            }
        } else {
            int k;
            cin >> k;

            const Data2 &f = tree2.val[rt2[1]];

            int ans = 0;

            for (int i = 0; i < m; ++i) {
                int cur = (f[i][0] + f[i][1] + f[i][2] + f[i][3]) % mod;

                if (parity[i & k])
                    cur = (mod - cur);

                add_mod(ans, cur);
            }

            ans = ans * ivm % mod;

            cout << ans << '\n';
        }
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 12ms
memory: 14380kb

input:

2000 64
22 28 32 54 9 33 24 58 9 22 40 21 2 38 61 15 2 34 37 37 60 58 23 50 30 46 17 31 48 53 15 11 29 5 63 35 22 3 1 42 43 36 21 20 23 56 7 46 43 32 1 2 17 9 16 3 6 56 37 6 11 31 47 55 11 63 27 54 43 39 59 13 12 52 39 9 36 58 29 47 25 38 56 12 5 38 58 34 26 52 40 12 26 44 20 7 43 10 45 6 21 53 41 5...

output:

3926
3921
3971
3534
3881
3912
3613
3791
4109
3763
3710
3590
3761
3988
3572
3703
4098
3703
3753
3588
3756
3889
3598
3723
3935
3722
3778
3536
3731
3977
3549
3755
3915
3931
3545
3709
3922
3789
3718
3566
3735
3900
3514
3785
3890
3748
3737
3611
3738
3957
3549
3692
3903
3779
3758
3576
3711
3900
3548
3803
...

result:

ok 64 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 14376kb

input:

2000 64
46 28 7 47 40 55 35 2 53 26 60 21 51 62 25 61 39 30 22 46 32 54 0 0 39 3 35 46 27 1 28 22 54 4 51 12 63 14 10 31 27 38 62 47 54 21 59 14 19 22 15 10 23 28 47 26 3 26 63 62 52 60 49 4 16 56 53 24 56 40 27 50 63 21 51 5 29 20 26 3 60 7 4 37 42 47 9 13 43 33 0 40 24 5 6 63 38 10 5 57 40 4 29 42...

output:

1685
2295
2052
1595
2204
1517
1268
1785
1890
2004
1929
1515
2095
1472
1277
1767
1395
1735
1877
1586
1780
1495
1544
2026
1394
1703
1982
1482
1898
1400
1697
2014
1711
1974
1978
1734
1861
1450
1396
1753
1560
2059
2035
1567
1960
1438
1471
1852
1330
1862
1835
1446
1853
1586
1531
1989
1422
1728
1971
1261
...

result:

ok 64 lines

Test #3:

score: 5
Accepted
time: 8ms
memory: 14356kb

input:

2000 64
11 29 7 63 56 9 58 15 51 6 40 8 17 23 27 6 17 16 36 8 60 24 26 10 37 22 60 26 3 54 53 30 38 60 62 23 7 53 36 13 42 29 3 40 28 48 30 51 11 7 37 56 62 47 7 30 26 11 29 6 55 13 25 2 20 36 47 36 27 37 61 63 37 62 31 19 32 57 7 28 34 28 37 29 40 42 55 60 12 0 14 61 63 13 8 60 13 4 45 41 14 25 14 ...

output:

7242
7897
7980
7060
7601
7957
8083
7432
7814
7226
7067
7726
7968
7392
7418
8062
6576
7069
6969
6532
6260
6823
6762
6205
7162
6498
6642
7068
6899
6290
6282
6876
7448
7758
7793
7050
7357
7852
7973
7349
7773
7279
7158
7831
7899
7405
7421
7977
6320
7082
7003
6482
6299
6875
6757
6316
7106
6415
6534
7007
...

result:

ok 64 lines

Test #4:

score: 5
Accepted
time: 4ms
memory: 14260kb

input:

2000 64
53 27 44 42 14 35 59 31 44 30 20 30 17 36 18 2 6 34 60 0 32 38 1 13 13 11 8 19 54 59 36 35 22 1 30 20 0 16 48 9 48 23 43 2 27 9 38 38 59 36 41 8 0 54 16 12 11 15 57 7 52 46 51 30 25 55 54 56 43 61 4 18 61 45 45 11 59 34 38 18 14 10 5 9 60 13 63 1 56 12 49 7 16 44 24 18 51 39 31 40 12 63 35 2...

output:

3788
3854
4227
4205
3967
3772
4233
4196
3836
3774
4152
4049
3796
3715
4161
4229
5693
5529
5575
5589
5055
5095
5710
5660
5481
5443
5558
5617
5051
4950
5634
5713
4342
4123
3687
3656
4228
4171
3709
3798
4130
4134
3724
3711
4108
4230
3848
3744
5488
5652
5559
5353
5651
5651
5044
5074
5643
5568
5432
5491
...

result:

ok 64 lines

Test #5:

score: 5
Accepted
time: 80ms
memory: 163792kb

input:

30000 8
4 0 1 0 4 3 4 3 7 1 3 2 5 4 1 1 0 4 7 5 5 0 3 4 4 5 2 4 2 5 0 3 3 7 0 3 5 3 3 1 1 2 3 4 2 2 6 6 3 2 6 4 0 6 4 7 6 2 2 7 6 2 4 4 7 4 3 1 6 7 1 6 7 1 5 5 5 0 6 7 0 5 5 6 7 2 1 7 2 3 0 3 5 7 6 5 1 7 6 2 4 5 1 3 2 3 2 7 7 3 5 4 6 0 4 3 1 2 3 3 0 7 2 3 4 4 0 3 2 3 2 3 3 2 3 4 7 0 4 5 2 0 4 5 0 4 ...

output:

4073
6368
6368
48
8870
3067
412
2285
7762
3338
9435
6225
831
8860
5590
422
5378
8494
6365
2383
8494
4008
5632
2374
4614
308
2449
2339
4973
1843
1843
7090
2149
6773
1649
700
6950
5776
2348
916
8754
5344
7957
6235
5152
3991
8762
832
3627
6487
6196
7373
4708
8751
8616
1880
1880
7078
2365
2546
7652
9491...

result:

ok 19993 lines

Test #6:

score: 5
Accepted
time: 79ms
memory: 163912kb

input:

30000 8
7 5 1 6 6 1 7 4 0 0 3 7 3 2 2 5 1 7 6 4 3 2 5 4 3 5 6 1 5 4 2 7 3 6 6 5 7 3 7 2 6 5 5 2 5 2 7 6 4 3 5 2 3 0 2 2 4 6 3 5 5 4 4 1 3 2 6 3 3 7 2 1 0 2 1 3 1 6 0 6 1 1 1 5 3 2 7 5 0 3 7 1 5 5 3 0 0 3 1 5 6 5 0 4 6 0 3 7 5 3 3 7 2 6 7 5 4 0 3 4 3 0 5 4 1 3 2 3 4 7 0 1 2 6 2 0 7 7 6 2 6 6 5 4 0 6 ...

output:

8110
4669
3774
3008
8679
7405
8768
1894
7405
1627
2886
4023
102
6275
102
7682
6488
1609
7623
9120
4202
7967
781
3301
3301
2451
5644
8396
932
8221
7084
2535
7419
873
5679
9037
9028
291
1515
2829
5839
349
3316
349
5539
4132
4132
5874
4132
8533
5250
6771
2977
1199
2654
2045
2217
7959
7959
1612
1939
515...

result:

ok 19993 lines

Test #7:

score: 5
Accepted
time: 51ms
memory: 164316kb

input:

30000 8
4 3 2 5 2 2 7 6 1 2 1 3 1 4 1 3 7 2 1 4 1 3 5 5 7 3 1 3 0 7 7 6 1 3 2 0 5 6 5 5 3 1 3 0 7 6 5 7 1 0 4 3 4 6 5 6 0 7 6 2 3 2 2 2 6 0 0 6 2 4 4 1 7 1 4 5 3 6 1 2 0 2 1 6 6 2 3 6 3 1 5 3 0 2 1 2 0 6 2 5 3 4 3 2 4 4 1 7 5 7 3 1 5 6 3 2 1 5 1 1 0 7 2 7 6 4 0 0 2 0 5 0 6 2 0 3 0 1 0 2 3 1 0 5 5 0 ...

output:

1761
5276
5276
7688
305
4400
4400
8495
6150
475
7960
4190
4250
9493
9629
8661
103
2544
1114
2389
2546
2447
3419
1172
2957
989
6740
6273
1908
1466
3518
1236
4657
1862
7861
6572
3151
3458
4141
8629
9066
619
5841
7983
5611
5575
581
7710
2622
3831
4965
2296
877
749
5338
1540
1540
5728
8390
6432
3562
159...

result:

ok 19993 lines

Test #8:

score: 5
Accepted
time: 50ms
memory: 165100kb

input:

30000 8
1 3 7 6 6 0 0 2 4 0 0 1 5 0 6 5 2 3 2 2 7 4 5 2 7 7 1 3 3 6 6 5 2 7 2 2 4 0 1 1 2 0 4 7 1 2 3 6 7 0 1 4 3 7 7 2 1 1 3 4 4 2 7 6 0 7 1 7 4 4 3 3 6 4 5 3 3 5 3 1 7 1 6 2 3 2 0 3 7 7 1 5 0 7 7 7 1 2 0 2 3 1 0 4 4 4 1 2 1 1 4 2 2 6 1 2 4 7 6 4 2 0 1 0 5 4 5 5 3 0 0 7 4 4 5 6 5 5 2 6 1 3 2 1 1 6 ...

output:

3162
6252
5044
3893
5518
2902
7749
1351
1162
1162
4488
4315
1088
8240
7170
4577
7475
1509
1509
836
7372
7805
8868
668
5414
3867
5149
764
764
8538
8538
1060
7229
6651
2206
4324
3964
4969
4969
529
31
3591
5287
8099
1927
7160
8099
2522
5716
988
7264
2237
3035
3828
1733
3241
4630
1421
1723
2363
781
2804...

result:

ok 19993 lines

Test #9:

score: 5
Accepted
time: 283ms
memory: 163824kb

input:

30000 128
24 14 81 59 101 60 92 42 72 73 116 57 34 110 115 120 94 105 123 98 85 46 48 42 30 83 81 35 102 105 86 17 104 91 5 88 66 103 11 123 3 50 46 55 81 45 0 9 88 4 22 33 74 89 108 116 49 7 117 24 83 70 96 73 51 91 69 74 81 110 47 40 64 60 117 21 103 85 113 109 79 55 17 28 126 47 90 58 5 26 87 14 ...

output:

1650
2556
3659
9223
6038
636
3917
2775
2698
4868
3929
4972
1726
2799
9857
1037
4123
1780
5484
3351
4030
3967
3112
2250
1411
3423
985
4574
1609
1914
1321
4735
2849
7729
2707
2536
6585
3154
2124
5287
3728
6181
2640
856
3166
1533
5680
7705
8309
1241
4729
5421
9852
1970
2989
3525
769
4493
4405
3881
2885...

result:

ok 19993 lines

Test #10:

score: 5
Accepted
time: 263ms
memory: 167028kb

input:

30000 128
35 77 54 36 41 126 18 8 28 20 37 115 21 27 43 47 45 81 29 115 117 98 18 121 71 91 124 51 70 76 10 62 82 9 112 2 56 113 112 23 106 54 108 23 105 119 60 100 84 51 54 49 90 107 104 15 31 45 118 28 60 68 53 16 47 21 62 9 60 71 95 84 51 73 79 75 14 22 108 3 19 78 74 32 126 22 62 71 43 124 0 30 ...

output:

3153
5958
5958
1718
3624
5860
2653
5495
3561
3350
1242
2540
4817
5217
4566
995
4755
325
2573
5179
2601
4137
5260
3340
1846
3337
3773
2228
3217
8590
5349
1542
4300
3655
4659
1057
1117
4600
4837
4515
4589
2745
2984
2015
3692
1133
3571
4731
5299
3251
3649
2592
2784
3919
1881
4151
4477
697
4255
4627
375...

result:

ok 19993 lines

Test #11:

score: 5
Accepted
time: 53ms
memory: 153900kb

input:

30000 4
1 3 0 0 1 0 3 0 0 2 0 1 2 3 0 1 0 0 1 0 1 2 0 0 0 0 3 2 3 2 3 2 1 2 2 3 2 0 3 3 2 1 1 1 1 0 1 1 0 3 2 0 0 3 2 1 0 1 0 0 3 0 3 3 1 2 2 2 2 2 0 3 3 1 1 2 2 1 3 2 2 2 0 2 1 3 2 2 2 3 0 0 3 2 0 2 1 1 1 1 0 1 0 3 3 1 2 0 3 2 3 2 2 0 2 1 1 0 3 3 3 3 3 0 1 3 0 1 2 1 3 0 2 1 1 1 1 2 0 3 0 2 1 1 3 3 ...

output:

1645
2593
3204
1645
1349
1655
1353
1654
1354
1354
1654
1354
1654
1654
2590
3190
2594
1357
1650
3190
1650
3190
3190
2594
1650
3280
3280
1267
1267
3280
1267
1560
3280
4302
9949
4302
4902
4302
4302
4302
9948
9878
4916
9878
9639
9639
9878
9878
4372
9639
4916
4390
9621
9864
4930
4930
4392
9619
4930
9864
...

result:

ok 19993 lines

Test #12:

score: 5
Accepted
time: 42ms
memory: 153600kb

input:

30000 4
0 0 1 3 3 2 3 1 3 0 2 2 3 2 0 0 0 3 3 3 3 1 0 0 3 0 3 0 1 3 2 2 0 0 1 3 0 1 2 1 1 0 2 0 2 2 2 2 3 0 2 3 2 0 2 3 1 2 1 0 0 0 1 3 0 1 1 2 1 1 1 2 3 0 2 2 0 2 1 2 1 0 0 2 2 3 0 0 3 3 0 2 2 2 0 1 2 1 0 2 1 2 3 2 1 1 2 3 1 2 0 2 0 0 3 2 3 2 3 1 0 0 3 1 3 2 1 0 3 1 2 0 3 3 0 1 3 2 1 2 2 2 2 3 0 1 ...

output:

8055
9995
8062
9995
7119
7120
7120
7120
7120
5147
5147
7120
5147
9982
5150
5
5165
5165
5
7
8051
7
7100
8057
8057
5157
7
7124
8033
23
7124
7076
8081
5188
5188
9983
5188
5188
8082
8082
7076
9982
9982
9982
5188
5340
9830
5340
8000
7158
8000
8000
8000
5340
5340
5340
5340
7158
5340
8000
7158
8000
9830
71...

result:

ok 19993 lines

Test #13:

score: 5
Accepted
time: 55ms
memory: 153480kb

input:

30000 4
0 0 3 1 1 3 0 2 0 2 1 1 3 2 1 3 0 1 0 1 3 1 2 3 3 0 3 2 1 2 3 2 3 1 2 1 3 3 3 0 0 1 3 1 2 3 3 3 2 0 0 0 3 1 0 3 0 1 1 0 3 1 2 1 3 0 0 0 0 2 1 1 0 3 2 0 2 3 3 3 3 0 2 1 2 2 1 3 2 3 3 3 0 1 2 2 3 2 1 0 3 3 0 1 0 2 0 1 3 0 1 0 0 0 3 2 2 1 2 0 2 3 3 1 1 3 1 0 2 1 2 2 0 1 3 0 2 2 2 1 2 0 1 2 0 2 ...

output:

9383
4073
7824
7824
9383
4710
7824
9383
4710
4710
7824
4711
4073
9383
4710
9381
7824
1189
2740
2741
702
702
1188
702
1345
1196
694
695
1196
1196
1338
2747
2747
695
2747
708
1350
2735
2735
1075
1451
1087
828
2622
1087
1087
828
828
1087
1428
839
839
2627
1025
896
1366
2689
896
896
1366
2689
896
1025
1...

result:

ok 19993 lines

Test #14:

score: 5
Accepted
time: 55ms
memory: 156148kb

input:

30000 4
0 1 0 1 3 0 2 3 1 1 1 1 0 1 3 2 3 3 1 2 3 0 0 2 0 2 1 3 3 2 2 0 1 1 2 2 2 0 2 1 2 2 3 2 3 2 0 1 0 1 0 3 0 3 0 2 3 0 0 3 3 0 0 0 3 1 2 1 1 1 1 2 0 3 0 1 1 3 0 3 3 0 3 3 0 3 3 0 0 2 1 3 1 2 0 3 1 2 2 1 0 3 0 1 1 3 0 3 0 2 3 1 2 1 3 3 0 0 2 3 3 3 1 3 0 0 0 0 2 1 1 2 2 1 2 2 3 0 1 2 3 3 2 0 3 0 ...

output:

9331
5467
9331
4870
9331
5467
5467
8975
9331
9331
4870
8975
9331
9331
9331
4870
8975
9331
4871
4871
4871
9332
4870
9334
4888
4896
4896
8963
5456
8963
5456
9328
8963
4896
5456
4896
8963
4921
5445
4921
5445
5445
4921
4921
5445
5445
4921
8939
4921
9340
8939
8939
9340
9340
5445
8939
9340
4919
8939
9339
...

result:

ok 19993 lines

Test #15:

score: 5
Accepted
time: 57ms
memory: 155872kb

input:

30000 4
1 1 3 1 0 0 2 1 3 0 3 0 2 1 0 2 2 1 1 2 0 0 2 2 3 1 0 3 1 2 0 0 0 3 1 3 1 2 3 0 0 3 0 0 0 0 2 2 3 0 0 3 2 1 3 2 1 0 0 0 0 3 2 1 3 2 1 1 2 2 0 3 3 1 0 3 3 1 0 0 3 3 2 0 2 0 1 3 1 2 0 1 1 0 1 2 2 3 0 3 0 0 2 1 0 3 3 0 1 2 0 2 1 1 1 0 1 3 1 3 2 2 0 2 1 3 3 3 3 3 1 0 0 2 2 0 0 2 1 1 1 0 0 1 1 2 ...

output:

7588
4800
4800
4746
6883
5506
6882
6882
6882
6475
6475
4747
6883
5505
6883
6883
4747
4747
5505
6880
5508
6880
6478
6478
5508
6478
6478
6478
4744
5507
4745
5507
4745
4746
4746
6881
5506
4746
4746
5506
6477
5506
5506
6477
4746
6881
6881
6882
4746
5506
5506
6542
6816
6817
4887
6817
6817
6818
6818
4857
...

result:

ok 19993 lines

Test #16:

score: 5
Accepted
time: 270ms
memory: 156788kb

input:

30000 128
36 19 121 28 96 113 59 94 39 101 47 34 56 86 82 88 98 10 10 110 61 86 61 45 59 9 113 44 18 112 77 79 3 71 34 72 62 76 91 67 89 88 11 28 51 120 25 22 86 49 82 107 118 39 99 102 100 24 49 79 23 118 61 110 101 101 66 16 47 21 106 58 17 54 110 102 22 52 85 40 48 25 64 97 11 113 123 111 9 111 3...

output:

6927
4221
5985
1834
1277
7789
1995
4920
4003
1269
8066
6179
6349
4870
5927
9227
5485
466
2931
1921
1630
3834
6432
2368
2655
968
4674
2252
4874
375
6097
8578
2663
1679
6567
9161
2247
7589
6996
9034
7556
5424
4539
9399
9660
2947
4516
4365
3784
5260
2583
7078
2747
3237
1515
4779
2788
9157
4772
1074
777...

result:

ok 19993 lines

Test #17:

score: 5
Accepted
time: 232ms
memory: 155784kb

input:

30000 128
5 118 100 119 118 37 44 3 102 77 102 64 58 65 70 2 3 40 18 66 81 114 64 57 122 55 90 41 29 112 104 6 87 25 20 125 33 77 61 117 57 16 27 32 58 50 110 115 94 88 75 39 121 64 125 33 111 16 51 59 32 112 82 54 4 82 54 97 22 67 28 101 78 117 41 122 7 125 59 71 71 61 62 86 83 85 68 111 9 17 106 6...

output:

7870
3095
9783
9760
4450
1348
3731
9156
5651
8792
1535
6166
2058
1223
1945
6115
6135
553
3125
9942
3495
1098
1098
8184
2079
6103
8186
1396
477
1468
2009
7754
6191
7407
2216
3458
732
8057
2047
5731
5522
8638
3183
8290
1256
1053
9761
9879
1426
6003
876
1405
904
8720
4095
3390
8845
8720
1197
58
5958
76...

result:

ok 19993 lines

Test #18:

score: 5
Accepted
time: 254ms
memory: 158492kb

input:

30000 128
59 24 4 95 47 19 58 33 54 96 10 86 53 101 111 31 32 100 75 117 126 51 16 31 98 126 82 105 102 71 1 58 99 45 126 33 126 115 36 6 93 63 65 110 25 11 50 23 56 37 86 11 64 27 83 90 110 78 22 78 22 111 32 0 34 86 63 34 12 29 119 108 64 106 6 31 84 112 92 46 60 47 116 11 91 43 98 109 93 70 68 66...

output:

6537
7133
7255
5036
9521
699
8957
3364
2754
5036
8431
1605
8601
7272
9578
4927
7312
4640
679
8632
223
8977
6067
8370
4324
2735
2735
4652
1223
8135
1841
581
9531
8113
9546
3258
5816
6399
889
9731
2192
7647
8091
3317
6770
3317
8402
6384
3559
9541
736
5685
5840
8801
9366
946
2680
558
5276
832
2016
207
...

result:

ok 19993 lines

Test #19:

score: 5
Accepted
time: 260ms
memory: 159020kb

input:

30000 128
124 118 118 36 60 31 38 60 118 51 55 55 103 110 7 38 49 69 106 57 0 15 111 79 26 50 84 40 119 28 92 124 78 51 97 33 76 29 87 44 49 117 82 118 4 28 38 92 40 86 6 74 125 54 79 125 66 110 102 66 96 106 6 14 12 75 55 122 21 39 90 83 50 86 90 120 41 34 124 45 17 112 97 114 31 29 118 1 49 76 82 ...

output:

9314
6169
1042
9055
8042
4156
9445
5594
7244
9877
4824
9055
8916
7073
5370
7544
8916
8759
7078
7062
7736
6695
8771
8570
6231
478
5826
6789
6571
7730
5826
4531
7108
6028
2820
9367
5092
6190
7981
7609
8835
8072
7778
821
4609
8752
7395
8191
7373
5722
6828
7476
4872
5586
7539
478
8226
8177
8372
6981
869...

result:

ok 19993 lines

Test #20:

score: 5
Accepted
time: 252ms
memory: 158780kb

input:

30000 128
121 86 26 36 67 117 72 19 14 69 76 94 31 76 50 106 89 84 104 122 98 28 82 55 68 38 22 46 94 108 95 92 78 41 71 8 65 70 44 69 36 54 12 125 49 64 48 48 19 93 46 113 54 4 39 50 125 23 43 124 71 79 60 79 20 29 3 11 81 29 33 92 88 83 54 90 32 78 117 60 20 2 90 31 66 58 46 119 79 40 80 2 43 58 1...

output:

9130
9061
7961
3919
3090
1571
6960
2315
1742
2682
4877
8157
2028
1960
1431
567
8868
9397
3023
9516
7945
2678
1431
5819
9608
8749
4182
7247
3879
9071
4090
7247
459
1734
7281
2678
1431
9608
7201
9268
3115
1955
5004
9449
8566
3103
3042
4228
969
1097
2716
4133
8031
7191
6842
6276
8954
64
9388
9458
9811
...

result:

ok 19993 lines