1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace IO {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], * iS, * iT, obuf[SIZE], * oS = obuf, * oT = obuf + SIZE - 1; char _st[55]; int _qr = 0;
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher_ { ~Flusher_() { flush(); } }io_flusher;
struct Fastin {
inline char gc() { return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++); }
inline void operator()() {}
inline void operator()(char& IEE) { IEE = gc(); }
template<class T1, class ...T2> inline void operator()(T1& IEE, T2&... ls) { T1 __ = 0, ___ = 1; char ch; while (!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___; do { __ = (__ << 1) + (__ << 3) + (ch ^ 48); } while (isdigit(ch = gc())); __ *= ___; IEE = __; operator()(ls...); }
template<class... T2> inline void operator()(char& IEE, T2&... ls) { IEE = gc(); operator()(ls...); }
template<typename T> friend Fastin& operator>>(Fastin& fin, T& val) { fin(val); return fin; }
}fin;
struct Fastout {
inline void putc_(char _x) { *oS++ = _x; if (oS == oT) flush(); }
inline void operator()() {}
inline void operator()(char IEE) { putc_(IEE); }
inline void operator()(const char* str) { while (*str != '\0') putc_(*str++); }
inline void operator()(const std::string& IEE) { operator()(IEE.c_str()); }
template<class... T2> inline void operator()(const char IEE, T2... ls) { putc_(IEE); operator()(ls...); }
template<class... T2> inline void operator()(const char* str, T2... ls) { while (*str != '\0') putc_(*str++); operator()(ls...); }
template<class... T2> inline void operator()(const std::string& IEE, T2... ls) { operator()(IEE.c_str(), ls...); }
template<class T1, class ...T2> inline void operator()(T1 IEE, T2... ls) { if (!IEE) putc_('0'); if (IEE < 0) putc_('-'), IEE = -IEE; while (IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10; while (_qr) putc_(_st[_qr--]); operator()(ls...); }
template<typename T> friend Fastout& operator<<(Fastout& fout, const T& val) { fout(val); return fout; }
}fout;
}
using namespace IO;

Template 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace IO {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], * iS, * iT, obuf[SIZE], * oS = obuf, * oT = obuf + SIZE - 1; char _st[55]; int _qr = 0;
inline char gc() { return (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS++) : *iS++); }
inline void qread() {}
inline void qread(char& IEE) { IEE = gc(); }
template<class T1, class ...T2> inline void qread(T1& IEE, T2&... ls) { T1 __ = 0, ___ = 1; char ch; while (!isdigit(ch = gc())) ___ = (ch == '-') ? -___ : ___; do { __ = (__ << 1) + (__ << 3) + (ch ^ 48); } while (isdigit(ch = gc())); __ *= ___; IEE = __; qread(ls...); }
template<class... T2> inline void qread(char& IEE, T2&... ls) { IEE = gc(); qread(ls...); }
inline void flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
inline void putc_(char _x) { *oS++ = _x; if (oS == oT) flush(); }
inline void qwrite() {}
inline void qwrite(char IEE) { putc_(IEE); }
inline void qwrite(const char* str) { while (*str != '\0') putc_(*str++); }
inline void qwrite(const std::string& IEE) { qwrite(IEE.c_str()); }
template<class... T2> inline void qwrite(char IEE, T2... ls) { putc_(IEE); qwrite(ls...); }
template<class... T2> inline void qwrite(const char IEE, T2... ls) { putc_(IEE); qwrite(ls...); }
template<class... T2> inline void qwrite(const char* str, T2... ls) { while (*str != '\0') putc_(*str++); qwrite(ls...); }
template<class... T2> inline void qwrite(const std::string& IEE, T2... ls) { qwrite(IEE.c_str(), ls...); }
template<class T1, class ...T2> inline void qwrite(T1 IEE, T2... ls) { if (!IEE) putc_('0'); if (IEE < 0) putc_('-'), IEE = -IEE; while (IEE) _st[++_qr] = IEE % 10 + '0', IEE /= 10; while (_qr) putc_(_st[_qr--]); qwrite(ls...); }
struct Flusher_ { ~Flusher_() { flush(); } }io_flusher;
}