目前最快捷方便的 IO 板子是啥?
  • 板块学术版
  • 楼主TLEWA
  • 当前回复58
  • 已保存回复59
  • 发布时间2024/10/23 15:18
  • 上次更新2024/10/23 18:09:28
查看原帖
目前最快捷方便的 IO 板子是啥?
515129
TLEWA楼主2024/10/23 15:18

如题,放个我的

// using fread
#define INPUT_OPTIMIZE

// using fwrite
#define OUTPUT_OPTIMIZE

namespace IO {

#ifdef INPUT_OPTIMIZE
	#ifdef __unix__
		#include<sys/mman.h>
		inline static const char *_read_ptr = (const char *)mmap(nullptr, 0x7fffffff, 1, 2, 0, 0);
		#define getchar() (*_read_ptr++) 
	#else
	   	static char buf[1<<21], *p1 = buf, *p2 = buf;
	    #define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++
	#endif
#endif

    inline bool read(char *t) {
        memset(t, 0, sizeof t);
        char *pd = t, c = getchar();
        while (isspace(c)) c = getchar();
        while (!isspace(c)) *pd++ = c, c = getchar();
        return c == EOF;
    }

    template <typename T> 
    inline bool read(T &t) {
        t=0;T sgn=1;
        char c = getchar();
        while (!isdigit(c)) {if(c == '-')sgn *= -1;c = getchar();}
        while (isdigit(c)) t = (t << 3) + (t << 1) + (c ^ 48), c = getchar();
        t*=sgn;
        return c == EOF;
    }

    template <typename T, typename... Args> 
    inline bool read(T &t, Args&... args) {
        return read(t) ? 1 : read(args...);
    }

#ifdef OUTPUT_OPTIMIZE
    static char outbuf[1<<24], *out = outbuf;
    #define putchar(x) *out++ = x
    #define flush() fwrite(outbuf, 1, out - outbuf, stdout)
#else 
   #define flush() 0
#endif

    template 
    <typename T> 
    inline 
    void write(T x) {
        if (!x) return putchar('0'), void();
        static char t[9], p = 0;
        while (x) t[++p] = (x % 10) ^ 48, x /= 10;
        while (p) putchar(t[p--]);
    }

}

using namespace IO;
2024/10/23 15:18
加载中...