getchar_unlocked()快读
getchar_unlocked() 的速度比 fread() 略逊一筹,但是有代码短小精悍的优点,可以在比赛中直接使用
Code:
1 2 3 4 5 6 7 8 9 10
| namespace getchar_unlocked_fastread { const void read(int &x) { x = 0; int f = 1; char c = getchar_unlocked(); while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar_unlocked();} while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar_unlocked(); x *= f; } }using getchar_unlocked_fastread::read;
|
fread()快读
fread()快读是目前最快的快读,但是有读入的缓存区,占内存
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| namespace fread_fastread { const int S = 1 << 20; char buf[S], *H, *T; char getchar() { if(H == T) T = (H = buf) + fread(buf, 1, S, stdin); return (H == T) ? EOF : *H ++ ; } const void read(int &x) { x = 0; int f = 1; char c = getchar(); while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); x *= f; } } using fread_fastread::read;
|