QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449140#6. 玛里苟斯NOI_AK_ME100 ✓20ms5136kbC++2311.6kb2024-06-20 18:44:002024-06-20 18:44:00

Judging History

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

  • [2024-06-20 18:44:00]
  • 评测
  • 测评结果:100
  • 用时:20ms
  • 内存:5136kb
  • [2024-06-20 18:44:00]
  • 提交

answer

#include <algorithm>
#include <bit>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <sys/mman.h>
#include <sys/stat.h>
#ifndef __OY_HAMELXORBASE__
#define __OY_HAMELXORBASE__
namespace OY {
    namespace HAMEL {
        template <typename Tp, uint32_t MAX_WIDTH>
        struct MaskNodes {
            Tp m_val[MAX_WIDTH];
            Tp &operator[](uint32_t index) { return m_val[index]; }
            Tp operator[](uint32_t index) const { return m_val[index]; }
            uint32_t count() const {
                return std::count_if(m_val, m_val + MAX_WIDTH, [&](Tp x) { return x; });
            }
        };
        template <typename Tp>
        struct MaskNodes<Tp, 0> {
            static uint32_t s_width;
            std::vector<Tp> m_val = std::vector<Tp>(s_width);
            Tp &operator[](uint32_t index) { return m_val[index]; }
            Tp operator[](uint32_t index) const { return m_val[index]; }
            uint32_t count() const {
                return std::count_if(m_val.begin(), m_val.end(), [&](Tp x) { return x; });
            }
        };
        template <typename Tp>
        uint32_t MaskNodes<Tp, 0>::s_width = sizeof(Tp) << 3;
        template <typename Tp, uint32_t MAX_WIDTH>
        struct HamelXorBase {
            MaskNodes<Tp, MAX_WIDTH> m_masks;
            static void set_width(uint32_t w) {
                static_assert(!MAX_WIDTH, "MAX_WIDTH Must Be 0");
                MaskNodes<Tp, MAX_WIDTH>::s_width = w;
            }
            static constexpr uint32_t width() {
                if constexpr (MAX_WIDTH)
                    return MAX_WIDTH;
                else
                    return MaskNodes<Tp, MAX_WIDTH>::s_width;
            }
            template <typename Callback>
            void _dfs(uint32_t index, Tp mask, const std::vector<uint32_t> &next, Callback &&call) const {
                uint32_t i = next[index];
                if (~i)
                    _dfs(i, mask, next, call), _dfs(i, mask ^ m_masks[i], next, call);
                else
                    call(mask);
            }
            HamelXorBase() = default;
            HamelXorBase(Tp mask) : m_masks{} { insert(mask); }
            uint32_t insert(Tp mask) {
                for (uint32_t i = std::bit_width(mask) - 1; mask && ~i; i--)
                    if (mask >> i & 1)
                        if (!m_masks[i]) {
                            m_masks[i] = mask;
                            return i;
                        } else
                            mask ^= m_masks[i];
                return -1;
            }
            bool contains(Tp mask) const {
                for (uint32_t i = std::bit_width(mask) - 1; mask && ~i; i--)
                    if (m_masks[i] && (mask >> i & 1)) mask ^= m_masks[i];
                return !mask;
            }
            uint32_t base_count() const { return m_masks.count(); }
            Tp total_count() const { return Tp(1) << base_count(); }
            Tp kth(Tp k, Tp base = 0) const {
                Tp cnt = total_count(), ans = base;
                for (uint32_t i = width() - 1; cnt > 1 && ~i; i--)
                    if (m_masks[i]) {
                        cnt >>= 1;
                        if (k >= cnt) {
                            if ((ans ^ m_masks[i]) > ans) ans ^= m_masks[i];
                            k -= cnt;
                        } else if ((ans ^ m_masks[i]) < ans)
                            ans ^= m_masks[i];
                    }
                return ans;
            }
            Tp kth_in_total(Tp k, const Tp &total, Tp base = 0) const {
                Tp cnt = total, ans = base;
                for (uint32_t i = width() - 1; cnt > 1 && ~i; i--)
                    if (m_masks[i]) {
                        cnt >>= 1;
                        if (k >= cnt) {
                            if ((ans ^ m_masks[i]) > ans) ans ^= m_masks[i];
                            k -= cnt;
                        } else if ((ans ^ m_masks[i]) < ans)
                            ans ^= m_masks[i];
                    }
                return ans;
            }
            Tp rank(Tp mask) const {
                Tp cnt = total_count(), ans = 0;
                for (uint32_t i = width() - 1; ~i; i--)
                    if (m_masks[i]) {
                        cnt >>= 1;
                        if (mask >> i & 1) ans += cnt;
                    }
                return ans;
            }
            Tp rank_in_total(Tp mask, const Tp &total) const {
                Tp cnt = total, ans = 0;
                for (uint32_t i = width() - 1; ~i; i--)
                    if (m_masks[i]) {
                        cnt >>= 1;
                        if (mask >> i & 1) ans += cnt;
                    }
                return ans;
            }
            template <typename Callback>
            void enumerate(Callback &&call) const {
                std::vector<uint32_t> next(width() + 1, -1);
                for (uint32_t lst = width(), i = width() - 1; ~i; i--)
                    if (m_masks[i]) next[lst] = i, lst = i;
                _dfs(width(), 0, next, call);
            }
            bool is_bonded(uint32_t k1, uint32_t k2) const {
                for (uint32_t i = std::min(k1, k2); i != width(); i++)
                    if ((m_masks[i] >> k1 & 1) != (m_masks[i] >> k2 & 1)) return false;
                return true;
            }
            Tp query_max_bitxor(Tp base = 0) const {
                Tp ans = base;
                for (uint32_t i = width() - 1; ~i; i--)
                    if ((ans ^ m_masks[i]) > ans) ans ^= m_masks[i];
                return ans;
            }
            HamelXorBase<Tp, MAX_WIDTH> &operator+=(const HamelXorBase<Tp, MAX_WIDTH> &rhs) {
                for (uint32_t i = 0; i != width(); i++)
                    if (rhs.m_masks[i]) insert(rhs.m_masks[i]);
                return *this;
            }
            friend HamelXorBase<Tp, MAX_WIDTH> operator+(const HamelXorBase<Tp, MAX_WIDTH> &a, const HamelXorBase<Tp, MAX_WIDTH> &b) { return HamelXorBase<Tp, MAX_WIDTH>(a) += b; }
        };
    }
    template <uint32_t MAX_WIDTH, typename = typename std::enable_if<MAX_WIDTH>::type>
    using StaticHamelXorBase32 = HAMEL::HamelXorBase<uint32_t, MAX_WIDTH>;
    template <uint32_t MAX_WIDTH, typename = typename std::enable_if<MAX_WIDTH>::type>
    using StaticHamelXorBase64 = HAMEL::HamelXorBase<uint64_t, MAX_WIDTH>;
    using DynamicHamelXorBase32 = HAMEL::HamelXorBase<uint32_t, 0>;
    using DynamicHamelXorBase64 = HAMEL::HamelXorBase<uint64_t, 0>;
}
#endif


using u8 = unsigned char;
using u16 = unsigned short;
using u32 = unsigned;
using u64 = unsigned long long;

constexpr u64 buf_def_size = 262144, buf_flush_threshold = 32, string_copy_threshold = 512, E16 = 1e16, E12 = 1e12, E8 = 1e8, E4 = 1e4;

struct _io_t {
    u32 t_o[10000];
    constexpr _io_t() {
        for (u32 e0 = (48 << 0), j = 0; e0 < (58 << 0); e0 += (1 << 0)) {
            for (u32 e1 = (48 << 8); e1 < (58 << 8); e1 += (1 << 8)) {
                for (u32 e2 = (48 << 16); e2 < (58 << 16); e2 += (1 << 16)) {
                    for (u32 e3 = (48 << 24); e3 < (58 << 24); e3 += (1 << 24)) {
                        t_o[j++] = e0 ^ e1 ^ e2 ^ e3;
                    }
                }
            }
        }
    }
    void get(char *s, u32 p)const {
        *((int *)s) = t_o[p];
    }
};
constexpr _io_t _iot = {};
struct Qinf {
    explicit Qinf(FILE *fi): f(fi) {
        auto fd = fileno(f);
        fstat(fd, &Fl);
        bg = (char *)mmap(0, Fl.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0);
        p = bg, ed = bg + Fl.st_size;
        madvise(bg, Fl.st_size + 1, MADV_SEQUENTIAL);
    }
    ~Qinf() {
        munmap(bg, Fl.st_size + 1);
    }
    template<std::unsigned_integral T>Qinf &operator>>(T &x) {
        skip_space(), x = 0;

        for (; *p > ' '; ++p) {
            x = x * 10 + (*p & 15);
        }

        return *this;
    }
    u32 rgc() {
        skip_space();
        return *p++ ^ 48;
    }
private:
    void skip_space() {
        while (*p <= ' ') {
            ++p;
        }
    }
    FILE *f;
    char *bg, *ed, *p;
    struct stat Fl;
} qin(stdin);
struct Qoutf {
    explicit Qoutf(FILE *fi, std::size_t sz = buf_def_size): f(fi), bg(new char[sz]),
        ed(bg + sz - buf_flush_threshold), p(bg) {}
    ~Qoutf() {
        flush();
        delete[] bg;
    }
    void flush() {
        fwrite_unlocked(bg, 1, p - bg, f), p = bg;
    }
    Qoutf &operator<<(u64 x) {
        if (x >= E8) {
            u64 q0 = x / E8, r0 = x % E8;

            if (x >= E16) {
                u64 q1 = q0 / E8, r1 = q0 % E8;
                put4(q1), putb(r1 / E4), putb(r1 % E4);
            } else if (x >= E12) {
                put4(q0 / E4), putb(q0 % E4);
            } else {
                put4(q0);
            }

            putb(r0 / E4), putb(r0 % E4);
        } else {
            if (x >= E4) {
                put4(x / E4), putb(x % E4);
            } else {
                put4(x);
            }
        }

        chk();
        return *this;
    }
    Qoutf &operator<<(char ch) {
        *p++ = ch;
        return *this;
    }
private:
    void putb(u32 x) {
        _iot.get(p, x), p += 4;
    }
    void put4(u32 x) {
        if (x > 99) {
            if (x > 999) {
                putb(x);
            } else {
                _iot.get(p, x * 10), p += 3;
            }
        } else {
            put2(x);
        }
    }
    void put2(u32 x) {
        if (x > 9) {
            _iot.get(p, x * 100), p += 2;
        } else {
            *p++ = x + '0';
        }
    }
    void chk() {
        if (p > ed)
            [[unlikely]] {
            flush();
        }
    }
    FILE *f;
    char *bg, *ed, *p;
} qout(stdout);

#define endl '\n'
#define cin qin
#define cout qout

static constexpr uint32_t N = 100000;
int main() {
    uint64_t n, K;
    cin >> n >> K;
    if (K == 1) {
        uint64_t sum = 0;
        for (uint32_t i = 0; i < n; i++) {
            uint64_t x;
            cin >> x;
            sum |= x;
        }
        u64 tmp = sum >> 1;
        cout << tmp;
        if (sum & 1) cout << '.' << 5ull;
    } else if (K == 2) {
        OY::StaticHamelXorBase32<32> hxb{};
        uint32_t sum = 0;
        for (uint32_t i = 0; i < n; i++) {
            uint32_t x;
            cin >> x;
            hxb.insert(x);
            sum |= x;
        }
        uint64_t ans = 0;
        for (uint32_t j1 = 0; j1 < 32; j1++)
            if (sum >> j1 & 1)
                for (uint32_t j2 = 0; j2 < 32; j2++)
                    if (sum >> j2 & 1)
                        if (hxb.is_bonded(j1, j2))
                            ans += uint64_t(1) << (j1 + j2);
                        else
                            ans += uint64_t(1) << (j1 + j2 - 1);
        u64 tmp = ans >> 1;
        cout << tmp;
        if (ans & 1) cout << '.' << 5ull;
    } else {
        OY::StaticHamelXorBase32<21> hxb{};
        for (uint32_t i = 0; i < n; i++) {
            uint32_t x;
            cin >> x;
            hxb.insert(x);
        }
        uint32_t tot = hxb.total_count();
        __uint128_t ans = 0;
        hxb.enumerate([&](uint32_t mask) {
            __uint128_t prod = 1;
            for (uint32_t j = 0; j < K; j++) prod *= mask;
            ans += prod;
        });
        cout << u64(ans / tot);
        if (ans % tot) cout << '.' << 5ull;
    }
}

詳細信息

Test #1:

score: 5
Accepted
time: 2ms
memory: 5136kb

input:

93348 1
1
2
4
9
25
52
81
133
508
652
1903
3296
5019
14045
18897
39827
81761
164654
433137
873979
1760925
2191486
7119527
14976120
19550122
56863700
91579561
181786097
320782698
677088935
1847381903
2214472334
6489287469
15349585339
22417199361
64252243732
127008028892
253725946829
497102455446
10445...

output:

9223372036854775807.5

result:

ok single line: '9223372036854775807.5'

Test #2:

score: 5
Accepted
time: 2ms
memory: 5016kb

input:

96800 1
14051766699896359
7215410969988351
16776696067864826
7632921873870586
12557076885174912
9161735894052404
15980916402619673
17968380965733216
11261263426099215
1424382964472915
5728555547066265
14908601420989880
14030145822431125
16379643591472362
11558257546383490
5684152043872785
5196436283...

output:

9007199254740991.5

result:

ok single line: '9007199254740991.5'

Test #3:

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

input:

95221 1
541
541
61
544
376
61
61
325
1340
1625
856
869
376
325
1636
544
1145
1281
1145
1340
1636
1820
1820
1625
1820
0
61
1825
376
1145
325
1145
1340
325
376
1281
0
1820
325
1281
1820
541
325
869
1825
1820
1281
376
376
1625
856
856
1281
1825
1145
1340
376
1281
1281
869
541
856
1825
1281
1281
1092
54...

output:

958.5

result:

ok single line: '958.5'

Test #4:

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

input:

98533 1
3708816
4210066
1308040
5434845
7910693
1308040
340294
7907595
5097203
4782005
3775884
4045297
848253
7625599
340559
5751740
3039403
276563
2843160
7688810
1785775
3103042
5903375
3034992
583164
3976394
8231748
7898832
5109263
5912797
5494589
652238
7233072
4530959
340559
2529657
3502072
310...

output:

4194303.5

result:

ok single line: '4194303.5'

Test #5:

score: 5
Accepted
time: 11ms
memory: 4320kb

input:

99218 2
1
2
7
11
31
62
89
133
440
542
1168
3630
5715
9335
22179
46247
89580
194345
438141
1032713
1538482
3074213
5533309
10366154
24031543
55097817
83511187
173451015
536744384
812063048
1419004740
4033891637
4196467447
1019527648
3299473730
1996992967
3674463225
651220214
34624954
137660395
310456...

output:

6148914689089033557.5

result:

ok single line: '6148914689089033557.5'

Test #6:

score: 5
Accepted
time: 7ms
memory: 4352kb

input:

96578 2
2142966981
2057970579
650230902
614791007
2009993626
1503336264
1843254468
344954375
1034874026
1836303812
1330950372
1062930152
1808725968
1345032296
742153662
144209584
778791656
958176703
310646776
648544269
1589164918
1353992516
795183608
1551098207
1044570885
1275989152
746346323
161141...

output:

1537228671735387477.5

result:

ok single line: '1537228671735387477.5'

Test #7:

score: 5
Accepted
time: 9ms
memory: 4276kb

input:

94187 2
1957907055
3931003789
2005347316
2544301452
1497132383
3152717565
1181858491
3483019990
4170106259
4055750004
4003470954
1974284488
1144991575
2668423078
3471595561
1583551589
1406011571
708388628
2126694511
747605046
1718302214
2193548222
2669308194
2258324117
1472721468
834409926
398749751...

output:

6148914689089033557.5

result:

ok single line: '6148914689089033557.5'

Test #8:

score: 5
Accepted
time: 10ms
memory: 4152kb

input:

90891 2
118554447
298165489
188351639
377308761
367689478
178508150
442268442
264391947
57586167
382022377
172829829
36075824
406112676
126474848
330208701
92046913
326570291
291751316
14008758
231762663
354234446
533562288
449834557
532237997
2899563
171139218
93795221
116023039
132785778
243837301...

output:

96076791782135125.5

result:

ok single line: '96076791782135125.5'

Test #9:

score: 5
Accepted
time: 20ms
memory: 3956kb

input:

90619 3
1
3
7
10
28
36
124
186
424
906
1647
2462
6234
9933
27809
53072
68578
142700
362823
654554
1984087
157994
693201
322850
116492
610036
204838
1345906
696265
342996
1078802
1317315
835765
1523925
1145451
520990
1733279
1317634
1398717
983003
1114840
302148
1618973
1693935
686085
434399
247741
1...

output:

2305840810190962688

result:

ok single line: '2305840810190962688'

Test #10:

score: 5
Accepted
time: 6ms
memory: 3828kb

input:

99692 3
54966
49725
36175
19283
46374
36992
41651
19295
61003
31483
17700
62315
6815
36564
47174
40308
1218
27082
24730
17759
65206
17083
12912
49829
50463
58622
9856
251
16677
59372
17149
47128
28281
63288
44046
32455
2759
25380
39233
31057
36170
6518
15121
44269
16701
26455
53637
20422
61692
31173...

output:

70366596710400

result:

ok single line: '70366596710400'

Test #11:

score: 5
Accepted
time: 0ms
memory: 3664kb

input:

98665 3
210
27
27
110
0
188
0
129
188
201
244
38
188
239
210
83
129
27
188
188
244
38
167
27
188
110
154
0
129
210
0
244
27
154
244
154
83
244
72
110
239
244
117
167
110
129
83
201
72
244
129
110
0
61
38
239
72
110
27
188
38
72
129
201
83
210
201
201
117
154
201
83
239
38
0
83
129
129
72
239
188
72
...

output:

4177536

result:

ok single line: '4177536'

Test #12:

score: 5
Accepted
time: 5ms
memory: 3768kb

input:

93587 3
31263
13029
42528
12794
16841
26681
48758
3271
6993
4778
22541
23342
39968
28137
51098
8355
37051
50543
47728
30027
58097
46182
19500
29713
30216
4489
23204
45019
1170
54271
48866
41614
32405
21049
11722
5664
49886
6703
48026
5325
63960
11809
18302
60322
573
3774
60753
26681
57742
64934
4422...

output:

70366596710400

result:

ok single line: '70366596710400'

Test #13:

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

input:

99711 4
1
3
4
9
21
60
112
233
371
857
2008
3740
4360
8778
24463
63257
51889
62102
13543
14856
5708
21083
36755
51081
21762
38599
9190
63703
29413
41985
40595
4474
14114
5556
40949
56375
41901
16928
43079
31958
38357
52247
24836
59723
60762
62591
45398
46165
33783
11491
15363
35607
16225
58700
6431
5...

output:

3689208078685210760.5

result:

ok single line: '3689208078685210760.5'

Test #14:

score: 5
Accepted
time: 0ms
memory: 3664kb

input:

91509 4
437
94
988
94
898
94
567
994
172
172
96
94
599
395
956
327
956
677
395
295
709
94
599
898
763
295
667
880
395
281
956
709
846
898
763
677
521
295
62
204
395
994
599
172
172
784
172
880
469
295
567
599
295
395
62
0
295
96
994
814
880
898
617
677
880
327
880
677
377
677
281
846
146
521
763
0
3...

output:

219160771256.5

result:

ok single line: '219160771256.5'

Test #15:

score: 5
Accepted
time: 2ms
memory: 3748kb

input:

92430 4
18697
13758
12489
31927
1399
1399
15077
1399
15077
12489
18002
13758
2604
18002
19582
16274
17189
3931
16274
0
16274
16274
16274
31927
31927
19582
30363
15077
16274
2604
0
19582
0
12489
3931
15077
29676
18697
16274
31168
2604
12489
0
30363
13758
19582
19582
18002
15077
29676
0
29676
13758
29...

output:

265753624987159112.5

result:

ok single line: '265753624987159112.5'

Test #16:

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

input:

91817 4
6247
3781
6698
8841
466
8498
13838
3208
11300
4406
6773
1497
13734
3361
6581
15175
7079
3967
4766
5446
13228
589
12219
8557
5834
5461
14260
14484
8435
12850
13211
549
13698
13926
76
10251
13247
15115
3809
8983
15528
7172
11794
11156
12717
8498
10324
7614
14315
11264
1442
4457
1955
6247
2268
...

output:

14409319974865032.5

result:

ok single line: '14409319974865032.5'

Test #17:

score: 5
Accepted
time: 6ms
memory: 3656kb

input:

99478 5
1
3
5
9
26
35
86
164
420
1019
1088
3607
6424
4029
1253
2314
3020
7503
3077
3742
7766
846
929
7718
2395
5341
780
4323
7760
1906
5293
6795
711
3814
3962
1085
4728
5645
4355
1429
3901
6005
8091
6820
6829
4903
420
6523
722
6630
2979
7779
7
5045
8032
1083
1320
2955
1669
6485
34
7698
6811
434
5656...

output:

6146663120487753728

result:

ok single line: '6146663120487753728'

Test #18:

score: 5
Accepted
time: 2ms
memory: 3720kb

input:

99213 5
485
426
161
79
346
436
191
346
277
426
238
277
346
79
485
507
79
277
191
436
324
436
436
485
191
238
161
324
30
240
507
277
436
79
191
426
240
30
324
81
81
79
0
81
240
324
436
267
485
485
507
81
240
161
485
81
426
277
240
240
79
507
436
30
507
30
161
0
324
426
267
238
485
240
426
240
0
0
238...

output:

6472883376848

result:

ok single line: '6472883376848'

Test #19:

score: 5
Accepted
time: 2ms
memory: 3660kb

input:

99889 5
19
28
34
19
34
45
28
34
49
34
19
15
49
0
45
49
45
19
62
28
62
19
34
28
62
45
0
28
0
19
45
28
28
45
15
19
19
15
34
0
28
15
19
45
49
15
15
45
34
49
0
34
34
45
15
49
0
28
28
0
34
28
15
62
45
19
45
34
62
28
49
34
15
28
15
49
49
0
28
45
34
15
19
49
49
19
15
15
28
19
28
0
62
45
15
49
49
0
28
19
19...

output:

181127184

result:

ok single line: '181127184'

Test #20:

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

input:

99139 5
1894
178
1837
325
240
1987
155
2037
572
1211
631
146
1986
1557
576
1140
664
1632
502
489
1565
664
1230
630
2004
141
141
1222
1141
1836
1535
963
294
75
1265
1140
9
66
332
896
503
133
1503
794
427
471
1953
881
1982
2027
1961
1578
248
124
1013
1437
573
1597
1502
1579
1526
488
2005
1130
1091
173...

output:

5996021955078656

result:

ok single line: '5996021955078656'