快读快写及O(2)优化模板
作者:互联网
快读快写模板及O(2)优化
- 快读模板1
inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar(); return x*f; }
- 快读模板2
char *p1,*p2,buf[100000]; #define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++) int read() { int x=0,f=1; char ch=nc(); while(ch<48||ch>57) { if(ch=='-') f=-1; ch=nc(); } while(ch>=48&&ch<=57) x=x*10+ch-48,ch=nc(); return x*f; }
- 快写模板
void write(long long x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); return; }
- O(2)优化
#pragma GCC optimize(2)
标签:p2,ch,int,while,p1,快读,优化,模板 来源: https://www.cnblogs.com/Azily-note/p/15957343.html