e6nlaq/library

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:warning: 改行を出力する
(include/e6nlaq/io.hpp)

Depends on

Code

#pragma once

#define E6NLAQ_IO_HPP

#include <concepts>
#include <iostream>

#include "iostream.hpp"

namespace e6nlaq {
/**
 * @brief 改行を出力する
 */
inline void co() {
#ifdef USE_ENDL
    std::cout << std::endl;
#else
    std::cout << "\n";
#endif
}

/**
 * @brief 可変長引数で与えられた値を空白区切りで出力し、最後に改行する
 * @tparam Head 最初の引数の型
 * @tparam Tail 残りの引数の型パック
 * @param head 最初の引数
 * @param tail 残りの引数
 */
template <typename Head, typename... Tail>
inline void co(Head head, Tail... tail) {
    std::cout << head;

    if constexpr (sizeof...(tail) > 0) {
        std::cout << " ";
    }

    co(tail...);
}

/**
 * @brief 真偽値に応じて "YES" または "NO" を大文字で出力する
 * @tparam T boolに変換可能な型
 * @param b 真偽値
 */
template <typename T>
    requires std::convertible_to<T, bool>
inline void YESNO(T b) {
    co(b ? "YES" : "NO");
}

/**
 * @brief 真偽値に応じて "yes" または "no" を小文字で出力する
 * @tparam T boolに変換可能な型
 * @param b 真偽値
 */
template <typename T>
    requires std::convertible_to<T, bool>
inline void yesno(T b) {
    co(b ? "yes" : "no");
}

/**
 * @brief 真偽値に応じて "Yes" または "No" を先頭大文字で出力する
 * @tparam T boolに変換可能な型
 * @param b 真偽値
 */
template <typename T>
    requires std::convertible_to<T, bool>
inline void YesNo(T b) {
    co(b ? "Yes" : "No");
}

/**
 * @brief 条件に応じて異なるメッセージを出力する
 * @tparam T boolに変換可能な型
 * @tparam tr 真の場合に出力する値の型
 * @tparam fal 偽の場合に出力する値の型
 * @param b 条件
 * @param tru 真の場合に出力する値
 * @param fals 偽の場合に出力する値
 */
template <typename T, typename tr, typename fal>
    requires std::convertible_to<T, bool>
inline void outif(T b, tr tru, fal fals) {
    co(b ? tru : fals);
}

/**
 * @brief 標準入出力の高速化を行う
 * @note C++の標準入出力を高速化するための設定を行う
 */
inline void fastio() noexcept {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
}

}  // namespace e6nlaq
#line 2 "include/e6nlaq/io.hpp"

#define E6NLAQ_IO_HPP

#include <concepts>
#include <iostream>

#line 2 "include/e6nlaq/iostream.hpp"

#define E6NLAQ_IOSTREAM_HPP

#include <cassert>
#line 7 "include/e6nlaq/iostream.hpp"
#include <string>
#include <vector>

namespace e6nlaq {

#ifdef __GNUC__
namespace {
__int128_t parse(const std::string& s) {
    __int128_t ret = 0;
    for (const char c : s) {
        if ('0' <= c && c <= '9') {
            ret = 10 * ret + (c - '0');
        }
    }

    if (!s.empty() && s[0] == '-') {
        ret = -ret;
    }

    return ret;
}
}  // namespace

// https://kenkoooo.hatenablog.com/entry/2016/11/30/163533
inline std::ostream& operator<<(std::ostream& dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char* d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}

inline std::istream& operator>>(std::istream& is, __int128_t& value) {
    std::string tmp;
    is >> tmp;

    value = parse(tmp);

    return is;
}
#endif  // __GNUC__

template <typename T>
inline std::istream& operator>>(std::istream& is, std::vector<T>& v) {
#if defined(LOCAL) && !defined(ALLOW_ZERO_VEC_CIN)
    assert(v.size() != 0);
#endif
    for (auto& elem : v) {
        is >> elem;
    }

    return is;
}

}  // namespace e6nlaq
#line 9 "include/e6nlaq/io.hpp"

namespace e6nlaq {
/**
 * @brief 改行を出力する
 */
inline void co() {
#ifdef USE_ENDL
    std::cout << std::endl;
#else
    std::cout << "\n";
#endif
}

/**
 * @brief 可変長引数で与えられた値を空白区切りで出力し、最後に改行する
 * @tparam Head 最初の引数の型
 * @tparam Tail 残りの引数の型パック
 * @param head 最初の引数
 * @param tail 残りの引数
 */
template <typename Head, typename... Tail>
inline void co(Head head, Tail... tail) {
    std::cout << head;

    if constexpr (sizeof...(tail) > 0) {
        std::cout << " ";
    }

    co(tail...);
}

/**
 * @brief 真偽値に応じて "YES" または "NO" を大文字で出力する
 * @tparam T boolに変換可能な型
 * @param b 真偽値
 */
template <typename T>
    requires std::convertible_to<T, bool>
inline void YESNO(T b) {
    co(b ? "YES" : "NO");
}

/**
 * @brief 真偽値に応じて "yes" または "no" を小文字で出力する
 * @tparam T boolに変換可能な型
 * @param b 真偽値
 */
template <typename T>
    requires std::convertible_to<T, bool>
inline void yesno(T b) {
    co(b ? "yes" : "no");
}

/**
 * @brief 真偽値に応じて "Yes" または "No" を先頭大文字で出力する
 * @tparam T boolに変換可能な型
 * @param b 真偽値
 */
template <typename T>
    requires std::convertible_to<T, bool>
inline void YesNo(T b) {
    co(b ? "Yes" : "No");
}

/**
 * @brief 条件に応じて異なるメッセージを出力する
 * @tparam T boolに変換可能な型
 * @tparam tr 真の場合に出力する値の型
 * @tparam fal 偽の場合に出力する値の型
 * @param b 条件
 * @param tru 真の場合に出力する値
 * @param fals 偽の場合に出力する値
 */
template <typename T, typename tr, typename fal>
    requires std::convertible_to<T, bool>
inline void outif(T b, tr tru, fal fals) {
    co(b ? tru : fals);
}

/**
 * @brief 標準入出力の高速化を行う
 * @note C++の標準入出力を高速化するための設定を行う
 */
inline void fastio() noexcept {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
}

}  // namespace e6nlaq
Back to top page