快读模版

发布时间 2023-07-19 15:21:42作者: lyyi2003
namespace IO{
    const int maxn((1 << 21) + 1);

    char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, ch, st[55];
    int opt, tp;
    char Getc() {
        return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), (iS == iT ? EOF : *iS++)) : *iS++);
    }

    void Flush() {
        fwrite(obuf, 1, oS - obuf, stdout);
        oS = obuf;
    }

    void Putc(char x) {
        *oS++ = x;
        if (oS == oT) Flush();
    }
    
    template <class Int> void Input(Int &x) {
        for (opt = 1, ch = Getc(); ch < '0' || ch > '9'; ch = Getc()) opt = ch == '-' ? -1 : 1;
        for (x = 0; ch <= '9' && ch >= '0'; ch = Getc()) x = (x << 3) + (x << 1) + (ch ^ 48);
        x *= opt;
    }
    
    template <class Int> void Print(Int x) {
        if (!x) Putc('0');
        if (x < 0) Putc('-'), x = -x;
        while (x) st[++tp] = x % 10 + '0', x /= 10;
        while (tp) Putc(st[tp--]);
    }

    void Getstr(char *s) {
        for (ch = Getc(); ch < 'A' || ch > 'Z'; ch = Getc());
        for (; ch <= 'Z' && ch >= 'A'; ch = Getc()) *s++ = ch;
        *s = 0;
    }
    
    void Putstr(const char *s) {
        for (int i = 0, n = strlen(s); i < n; ++i) Putc(s[i]);
    }
}
using IO::Input;
using IO::Print;
using IO::Flush;