【模板】快速讀入
阿新 • • 發佈:2018-12-14
快讀模板
struct FastIO { static const int S=1e6; int wpos; char wbuf[S]; FastIO() : wpos(0) {} inline int gc(){ static char buf[S]; static int len=0,pos=0; if(pos==len) pos=0,len=fread(buf,1,S,stdin); if(pos==len) return 0; return buf[pos++]; } inline void rd(int &x) { int c=gc();x=0; for(;c<=32;c=gc()); for (;isdigit(c);c=gc()) x=x*10+c-'0'; } inline void wchar(int x) { if (wpos==S) fwrite(wbuf,1,S,stdout),wpos=0; wbuf[wpos++]=x; } inline void ot(int x,char cp) { static char s[30]; int nm=0; for(;x || !nm;) s[nm++]='0'+x%10,x/=10; for(--nm;~nm;--nm) wchar(s[nm]); wchar(cp); } ~FastIO() {if (wpos) fwrite(wbuf,1,wpos,stdout),wpos=0;} }io;