读入优化:
1 #include<cctype> 2 #define N 500010 3 inline char gc() 4 { 5 static char buf[N],*p1=buf,*p2=buf; 6 return p1==p2&&(p2=(p1=buf)+fread(buf,1,N,stdin),p1==p2)?EOF:*p1++; 7 } 8 inline void read(int &x) 9 { 10 char ch=0;x=0;int f=0; 11 while (!isdigit(ch)) ch=gc(),f^=ch=='-'; 12 while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc(); 13 f&&(x=-x); 14 }
输出优化
1 inline void write(int x) 2 { 3 if (x<0) putchar('-'),x=-x; 4 if (x>9) write(x/10); 5 putchar(x%10+48); 6 }