假快读:
比 cin
快,比 scanf
优雅,比 read
好写,
namespace fira {
struct IO { } io; inline void print(char x) {putchar(x);}
template <typename T> inline void read(T &x) {scanf("%d", &x);}
template <typename T> inline void print(T x) {printf("%d", x);}
template <typename T> IO &operator>>(IO &a, T &x) {return read(x), a;}
template <typename T> IO &operator<<(IO &a, T x) {return print(x), a;}
} using namespace fira;
这是真快读了:
在 linux 环境下可用 getchar_unlocked
,速度与 fread
大致相同,
namespace fira {
#ifndef _WIN32
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
struct IO { } io;
template <typename T> inline void read(T &x) {
x = 0; int f = 1; char ch = getchar();
while (ch< '0' or ch> '9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^48), ch = getchar();
x *= f;
}
template <typename T> inline void print(T x) {
static char t[20]; int top = 0;
if (x < 0) putchar('-'), x = -x;
do { t[++top] = x % 10, x /= 10; } while (x);
while (top) putchar(t[top--] + 48);
}
inline void print(char x) { putchar(x); }
template <typename T> IO &operator>>(IO &a, T &x) { return read(x), a; }
template <typename T> IO &operator<<(IO &a, T x) { return print(x), a; }
}
using namespace fira;