快读快输
为啥你们卡常都管我要快读啊 😅
我直接发出来得了 .
贺自 OI-wiki:
namespace IO {
constexpr int SIZE = (1 << 19);
char ibuf[SIZE], * pi = ibuf, * p2 = ibuf;
#define gc() (pi == p2 && (p2 = (pi = ibuf) + fread (ibuf, 1, SIZE, stdin), pi == p2) ? EOF : *pi++)
inline int rnt () {
int x = 0, w = 1; char c = gc ();
while (!isdigit (c)) { if (c == '-') w = -1; c = gc (); }
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = gc ();
return x * w;
}
char obuf[SIZE], * po = obuf;
inline void push (const char& c) {
if (po - obuf == 1 << 20) fwrite (obuf, 1, SIZE, stdout), po = obuf;
*po++ = c;
}
inline void wnt (int x) {
static int sta[35]; int top = 0;
if (x < 0) push ('-'), x = -x;
do { sta[top++] = x % 10, x /= 10; } while (x);
while (top) push (sta[--top] + '0');
return;
}
} // namespace IO
//Example:
int main () {
freopen ("tmp.in", "r", stdin);
int a = IO::rnt (), b = IO::rnt ();
IO::wnt (a + b);
IO::push ('\n');
fwrite (IO::obuf, 1, 1 << 20, stdout);
return 0;
}
注意到一次读入缓冲区的大量内容,你终端输入的话比较有问题,建议使用 freopen .
不过这个是仍然有一些兼容性的,比如说输入结尾 EOF,兼顾了负数,你要是想卡得更狠一下可以下面这种写法:
namespace IO {
constexpr int SIZE = (1 << 21);
char ibuf[SIZE], * pi = ibuf;
inline int rnt () {
int x = 0, w = 1; char c = *pi++;
while (!isdigit (c)) c = *pi++;
while (isdigit (c)) x = (x << 3) + (x << 1) + (c ^ 48), c = *pi++;
return x * w;
}
char obuf[SIZE], * po = obuf;
inline void wnt (int x) {
static int sta[35]; int top = 0;
do { sta[top++] = x % 10, x /= 10; } while (x);
while (top) *po++ = sta[--top] + '0';
return;
}
} // namespace IO
//Example:
int main () {
freopen ("tmp.in", "r", stdin);
fread (IO::ibuf, 1, IO::SIZE, stdin);
int a = IO::rnt (), b = IO::rnt ();
IO::wnt (a + b);
*IO::po++ = '\n';
fwrite (IO::obuf, 1, IO::SIZE, stdout);
return 0;
}
不能读负数,不过问题并不大 . 输入不为负的题非常常见 .
调大了 SIZE,一次性读入输出,这个可能需要根据题目输入输出量调整,一般 1 << 21 到 1 << 23 .
输出量不大你就别快输了 . 输入量也要到达一定规模才比较有效果 .