标签:++ map private reader read opera for std sys
卡常必备,平时要多写。万一复杂度不对卡常卡过去了呢。
劣质版:
#include<cstdio>
char gcbuf[1<<28];
inline char fgc() {
static int cur = 0, lim = 0;
cur++;
if(cur >= lim) {
lim = fread(gcbuf, 1, 1<<28, stdin);
cur = 0;
}
return gcbuf[cur];
}
inline int read() {
int a = 0, c = fgc(), w = 1;
for(; c < ‘0‘ || c > ‘9‘; c = fgc()) if(c == ‘-‘) w = -1;
for(; c >= ‘0‘ && c <= ‘9‘; c = fgc()) a = a * 10 + c - ‘0‘;
return a * w;
}
优质版:
#include<cstdio>
#include <sys/mman.h>
struct IObuf{
char *buf;
IObuf() : buf((char*)mmap(0, 1<<28, PROT_READ, MAP_PRIVATE, fileno(stdin), 0)) {}
operator int(){
int ret = 0, flag = 0;
while (*buf < 48) if (*buf++ == 45) flag = 1;
while (*buf > 32) ret = ret*10+*buf++-48;
return flag ? -ret : ret;
}
} reader;
标签:++ map private reader read opera for std sys
原文地址:https://www.cnblogs.com/utopia999/p/9691596.html