跳到正文

剪贴板

剪贴板 7cfs47lg

原文
剪贴板信息

剪贴板信息

收录
更新
C++
#include <bits/stdc++.h>
#include <bits/extc++.h>

#include <fcntl.h>
#include <unistd.h>
#include <immintrin.h>
#ifdef __linux__
#include <sys/mman.h>
#include <sys/stat.h>
#endif

namespace detail {
    struct InputHelper { alignas(64) std::uint32_t table[0x10000]; _GLIBCXX14_CONSTEXPR InputHelper() : table() { for (std::uint32_t i = 0; i != 0x10000; table[i++] = std::uint32_t(-1)); for (std::uint32_t i = 48; i != 58; ++i) for (std::uint32_t j = 48; j != 58; ++j) table[i << 8 | j] = (j & 15) * 10 + (i & 15); } };
    struct OutputHelper { alignas(64) std::uint32_t table[10000]; _GLIBCXX14_CONSTEXPR OutputHelper() : table() { for (std::uint32_t o = 0, i = 48; i != 58; ++i) for (std::uint32_t j = 48; j != 58; ++j) for (std::uint32_t k = 48; k != 58; ++k) for (std::uint32_t l = 48; l != 58; ++l) table[o++] = i | (j << 8) | (k << 16) | (l << 24); } };
    static _GLIBCXX14_CONSTEXPR InputHelper I = {};
    static _GLIBCXX14_CONSTEXPR OutputHelper O = {};
};

class Scanner {
    std::int32_t fd;
    char buffer[32 << 20], *i;
    template <typename Value> auto s2(Value& value) -> void { ~detail::I.table[*reinterpret_cast<std::uint16_t*>(i)] && (value = Value(value * 100 + detail::I.table[*reinterpret_cast<std::uint16_t*>(i)]), i += 2); }
    template <typename Value> auto s4(Value& value) -> void { s2(value), s2(value); }
public:
#ifdef __linux__
    Scanner(std::int32_t file = STDIN_FILENO) : fd(file) { struct stat status; fstat(fd, &status); i = reinterpret_cast<char*>(mmap(nullptr, status.st_size, PROT_READ, MAP_PRIVATE, fd, 0)); }
    ~Scanner() = default;
#else
    Scanner(std::int32_t file = STDIN_FILENO) : fd(file), i(buffer) { std::fread(buffer, sizeof(char), sizeof(buffer), fdopen(fd, "r")); }
    ~Scanner() = default;
#endif
    auto scan(std::uint32_t& value) -> void { for (s4(value = 0), s4(value), s2(value), std::isdigit(*i) && (value = value * 10 + (*i++ & 15)); __builtin_expect(std::isspace(*++i), 0); ); }
    auto scan(std::uint64_t& value) -> void { for (s4(value = 0), s4(value), s4(value), s4(value), s4(value), std::isdigit(*i) && (value = value * 10 + (*i++ & 15)); __builtin_expect(std::isspace(*++i), 0); ); }
    auto scan(std::int32_t& value) -> void { bool sign = *i == '-' && ++i; scan(reinterpret_cast<std::uint32_t&>(value)), sign && (value = -value); }
    auto scan(std::int64_t& value) -> void { bool sign = *i == '-' && ++i; scan(reinterpret_cast<std::uint64_t&>(value)), sign && (value = -value); }
    auto scan(double& value) -> void { bool sign = *i == '-' && ++i; std::uint64_t integerPart = 0; for (s4(integerPart), s4(integerPart), s2(integerPart); std::isdigit(*i); integerPart = integerPart * 10 + (*i++ & 15)); value = double(integerPart); if (*i == '.') { ++i; double frac = 0.0, divisor = 10.0; while (std::isdigit(*i)) frac += (*i++ & 15) / divisor, divisor *= 10.0; value += frac; } sign && (value = -value); while (__builtin_expect(std::isspace(*++i), 0)); }
    auto scan(char& value) -> void { value = *i++; while (__builtin_expect(std::isspace(*++i), 0)); }
    auto scan(char* value) -> void { std::int32_t mask; static __m256i space = _mm256_set1_epi8(sizeof(__m256i)); for (char* first = i; true; i += sizeof(__m256i)) if ((mask = _mm256_movemask_epi8(_mm256_cmpgt_epi8(space, _mm256_loadu_si256(reinterpret_cast<__m256i*>(i))))) && std::memcpy(value, first, std::size_t((i += __builtin_ctz(std::uint32_t(mask))) - first))) break; while (__builtin_expect(std::isspace(*++i), 0)); }
    auto scan(std::string& value) -> void { std::int32_t mask; static __m256i space = _mm256_set1_epi8(sizeof(__m256i)); for (char* first = i; true; i += sizeof(__m256i)) if ((mask = _mm256_movemask_epi8(_mm256_cmpgt_epi8(space, _mm256_loadu_si256(reinterpret_cast<__m256i*>(i))))) && (value.assign(first, i += __builtin_ctz(std::uint32_t(mask))), true)) break; while (__builtin_expect(std::isspace(*++i), 0)); }
    template <typename Value> auto operator>>(Value& value) -> Scanner& { return scan(value), *this; }
};

class Printer {
    std::int32_t fd;
    char buffer[32 << 20], *i;
    template <typename Value> auto np(Value value) -> void { value > 9 && (np(value / 10), true), *i++ = char(48 | value % 10); }
    template <typename Value> auto wp(Value value) -> void { std::memcpy(i, detail::O.table + value, 4), i += 4; }
public:
#ifdef __linux__
    Printer(std::int32_t file = STDOUT_FILENO) : fd(file), i(buffer) {}
    ~Printer() { write(fd, buffer, std::uint32_t(i - buffer)); }
#else
    Printer(std::int32_t file = STDOUT_FILENO) : fd(file), i(buffer) {}
    ~Printer() { std::fwrite(buffer, sizeof(char), std::size_t(i - buffer), fdopen(fd, "w")); }
#endif
    auto print(std::uint32_t value) -> void { value < 100000000 ? (value < 10000 ? np(value) : (np(value / 10000), wp(value % 10000))) : (np(value / 100000000), wp(value / 10000 % 10000), wp(value % 10000)); }
    auto print(std::uint64_t value) -> void { value < 100000000 ? (value < 10000 ? np(value) : (np(value / 10000), wp(value % 10000))) : (value < 1000000000000 ? np(value / 100000000), wp(value / 10000 % 10000), wp(value % 10000) : (value < 10000000000000000 ? np(value / 1000000000000), wp(value / 100000000 % 10000), wp(value / 10000 % 10000), wp(value % 10000) : (np(value / 10000000000000000), wp(value / 1000000000000 % 10000), wp(value / 100000000 % 10000), wp(value / 10000 % 10000), wp(value % 10000)))); }
    auto print(std::int32_t value) -> void { print(std::uint32_t(value < 0 ? *i++ = '-', -value : value)); }
    auto print(std::int64_t value) -> void { print(std::uint64_t(value < 0 ? *i++ = '-', -value : value)); }
    auto print(double value) -> void { value < 0 && (*i++ = '-', (value = -value)); std::uint64_t integerPart = std::uint64_t(value); print(integerPart); *i++ = '.'; std::uint64_t fractionPart = std::uint64_t((value - double(integerPart)) * 100000000.0); wp(fractionPart / 10000), wp(fractionPart % 10000); }
    auto print(char value) -> void { *i++ = value; }
    auto print(const char* value) -> void { const std::size_t length = std::strlen(value); std::memcpy(i, value, length), i += length; }
    auto print(const std::string& value) -> void { const std::size_t length = value.size(); std::memcpy(i, value.data(), length), i += length; }
    template <typename Value> auto operator<<(const Value& value) -> Printer& { return print(value), *this; }
};

namespace {
    using i64 = std::int64_t;
    constexpr auto Anon = 0x0908, Soyo = 0x0527, Tomori = 0x1122, Taki = 0x0809, Rana = 0x0222;

}

auto main() -> decltype('一生バンドを組んでくれますか?') {

    {
        std::cerr << "Duration = " << std::clock() << "ms.\n";
        return Anon & Soyo & Tomori & Taki & Rana;
    }
}