跳到正文

剪贴板

剪贴板 ca58g7pm

原文
剪贴板信息

剪贴板信息

收录
更新

究极快读

From Drifty.

C++
namespace IO {
    class FastI_s {
        static const size_t SIZE = 1 << 9;
        unsigned char buf[SIZE]; int p;
    public:
        FastI_s() :  p(0) {fread(buf + p, 1, SIZE - p, stdin);}
        void flush() {
            memmove(buf, buf + p, SIZE - p), fread(buf + SIZE - p, 1, p, stdin), p = 0;
        }
        FastI_s & operator >> (char & str) {
            str = getch(); while (isspace(str)) str = getch(); return * this;
        }
        template <class T> FastI_s & operator >> (T & x) {
            x = 0; p + 32 >= SIZE ? flush() : void();
            unsigned short flag = false;
            for (; !isdigit(buf[p]); ++p) flag = buf[p] == '-';
            if (flag) for (; isdigit(buf[p]); ++ p) x = x * 10 - buf[p] + 48;
            else      for (; isdigit(buf[p]); ++ p) x = x * 10 + buf[p] - 48;
            return * this;
        }
        char getch() {return buf[p ++];}
    };

    class FastO_s {
        static const size_t SIZE = 1 << 6;
        unsigned char buf[SIZE]; int p;
    public:
        FastO_s() : p(0) {}
        ~ FastO_s() {fwrite(buf, 1, p, stdout);}
        #define flush (fwrite(buf, 1, p, stdout), p = 0)
        template <class T>
        FastO_s & operator << (T x) {
            int len = 0, f = x < 0;
            p + 8 >= SIZE ? flush : 0;
            if (f) {buf[p ++] = 45; do buf[p + len] = - (x % 10) + 48, x /= 10, ++ len; while (x);}
            else   {do buf[p + len] = x % 10 + 48, x /= 10, ++ len; while (x);}
            for (unsigned short i = 0, j = len - 1; i < j; ++ i, -- j) swap(buf[p + i], buf[p + j]); p += len;
            return *this;
        }
        FastO_s & operator << (char x) {putch(x); return * this;}
        void putch (char ch) {p + 32 >= SIZE ? flush : 0; buf[p ++] = ch;}
    } ;
}
IO::FastI_s fin;
IO::FastO_s fout;