QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#449137#6. 玛里苟斯NOI_AK_MECompile Error//C++2312.0kb2024-06-20 18:36:542024-06-20 18:36:55

Judging History

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

  • [2024-06-20 18:36:55]
  • 评测
  • [2024-06-20 18:36:54]
  • 提交

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/stats.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<<(const char* x) {
        const u32 n = __builtin_strlen(x);
        for (u32 i = 0; i < n; ++i) *p++ = x[i];
        return *this;
    }
    Qoutf &operator<<(u32 x) {
        if (x >= E8) {
            put2(x / E8), x %= E8, putb(x / E4), putb(x % E4);
        } else if (x >= E4) {
            put4(x / E4), putb(x % E4);
        } else {
            put4(x);
        }

        chk();
        return *this;
    }
    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;
        }
        cout << sum / 2;
        if (sum & 1) cout << ".5";
    } 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);
        cout << ans / 2;
        if (ans & 1) cout << ".5";
    } 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 << uint64_t(ans / tot);
        if (ans % tot) cout << ".5";
    }
}

Details

answer.code:12:10: fatal error: sys/stats.h: No such file or directory
   12 | #include <sys/stats.h>
      |          ^~~~~~~~~~~~~
compilation terminated.