读写优化
优化一
#ifdef _WIN32
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#else
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template <typename T> inline void rd(T &x){
x = 0; int f = 1; char ch = getchar();
while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar();}
while(isdigit(ch)) x = (x<<1) + (x<<3) + (ch^48), ch = getchar();
x *= f;
}
template <typename T> inline void wt(T x){
if(x < 0) putchar('-'), x = -x;
if(x / 10 > 0) wt(x / 10); putchar(x % 10 + '0');
}
优化二
#define B 1 << 23
char buf[B], *p1 = buf, *p2 = buf;
#define g() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, B, stdin), p1 == p2) ? EOF : *p1++)
template <typename T> inline void rd(T &x) {
x = 0; int f = 0; char c = g();
for (; c < '0' || c > '9'; c = g())
f ^= c == '-';
for (; c >= '0' && c <= '9'; c = g())
x = (x << 3) + (x << 1) + (c ^ '0');
x = f ? -x : x;
}
char obuf[B], *O = obuf;
#define p(c) (O - obuf == B && (fwrite(obuf, 1, B, stdout), O = obuf), *O++ = (c))
template <typename T> void wt(T x) {
if (x < 0) x = -x, p('-');
if (x >= 10) wt(x / 10);
p(x % 10 ^ '0');
}
注意在代码末尾加上
fwrite(obuf, 1, O - obuf, stdout)
标签:10,ch,putchar,void,板子,define,getchar
From: https://www.cnblogs.com/xiaolemc/p/18363531