Last active
July 9, 2022 04:21
-
-
Save cgiosy/97766f45ced4153caab229d6c2be1571 to your computer and use it in GitHub Desktop.
Fast IO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace io { | |
| const signed IS=1<<22; | |
| char I[IS+1],*J=I; | |
| inline void daer(){char*p=I;while(*J)*p++=*J++;p[fread(p,1,I+IS-p,stdin)]=0;J=I;} | |
| template<int N=10,typename T=int>inline T getu(){if(J>=I+IS-64)daer();T x=0;int k=0;do x=x*10+(*J-'0');while(*++J>='0'&&++k<N);++J;return x;} | |
| struct f{f(){I[fread(I,1,IS,stdin)]=0;}}flu; | |
| }; | |
| using namespace io; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| namespace io { | |
| const signed IS=1<<20, OS=1<<18; | |
| char I[IS+1],*J=I,O[OS],*K=O; | |
| inline void daer(){char*p=I;while(*J)*p++=*J++;p[fread(p,1,I+IS-p,stdin)]=0;J=I;} | |
| template<int N=10,typename T=int>inline T getu(){if(J>=I+IS-64)daer();T x=0;int k=0;do x=x*10+(*J-'0');while(*++J>='0'&&++k<N);++J;return x;} | |
| template<int N=10,typename T=int>inline T geti(){bool e=*J=='-';J+=e;return(e?-1:1)*getu<N,T>();} | |
| inline void flush(){fwrite(O,1,K-O,stdout);K=O;} | |
| template<int N=10,char C='\n',typename T>inline void putu(T n){char s[N+7&~7],*p=s;int k=0;do*p++=n%10+48;while((n/=10)&&++k<N);do*K++=*--p;while(p!=s);*K++=C;if(K>=O+OS-64)flush();} | |
| template<int N=10,char C='\n',typename T>inline void puti(T n){if(n<0)*K++='-',n=-n;putu<N,C>(n);} | |
| struct f{f(){I[fread(I,1,IS,stdin)]=0;}~f(){flush();}}flu; | |
| }; | |
| using namespace io; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
함수
getu: unsigned형 입력 (음수가 아닌 정수)geti: signed형 입력 (정수)putu: unsigned형 출력 (음수가 아닌 정수)puti: signed형 출력 (정수)daer: 입력을 더 읽어들임flush: 버퍼에 쌓인 출력을 flush함.사용법
int x = getu();: 음수가 아닌 기본 자릿수(10자리) 정수 int형을 입력받음int x = geti<6>();: 6자리 정수 int형을 입력받음char x = getu<3, char>();: 음수가 아닌 3자리 정수 char형을 입력받음 (문자 입력 아님)long long x = geti<14, long long>();: 14자리 정수 long long 형을 입력받음1e9,10^9은 9자리가 아니라 10자리임putu(x),putu<17, long long>(x)처럼 하면 됨기타
IS: 입력 버퍼 크기1<<24정도면 차고 넘친다OS: 출력 버퍼 크기template<int N=10,typename T=int>10대신 다른 숫자를 써넣으면 기본 자릿수 바뀜int대신 다른 타입을 써넣으면 기본 타입이 바뀜putu함수에서 두 번째 템플릿 인자를' '로 넣으면 끝에 새 줄 대신 공백을 출력함*K++='7';처럼 직접 문자를 쓸 수 있긴 함getu에서return직전의++J를while(*++J<=' ');로, 딱 두 개까지만 들어오는 경우J+=*++J<=' ';처럼 고쳐주면 됨