快读快写
Fir 快读
1 inline int read() 2 { 3 int X=0,w=0; char ch=0; 4 while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} 5 while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); 6 return w?-X:X; 7 }
快写
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+'0'); 6 }
更快的 Sec 快读
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) char buf[1<<21],*p1=buf,*p2=buf; template <typename T> inline void read(T& X) { X=0;bool w=0; char ch=getchar(); while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar(); while(ch>='0'&&ch<='9') X=(X<<3)+(X<<1)+(ch^48), ch=getchar(); X=w?-X:X; }
fread读入
1 namespace IO { 2 #define BUF_SIZE 100000 3 bool IOerror = 0; 4 inline char nc() { 5 static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE; 6 if(p1 == pend) { 7 p1 = buf; 8 pend = buf + fread(buf, 1, BUF_SIZE, stdin); 9 if(pend == p1) { 10 IOerror = 1; 11 return -1; 12 } 13 } 14 return *p1++; 15 } 16 inline bool blank(char ch) { 17 return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; 18 } 19 inline void read(int &x) { 20 char ch; 21 while(blank(ch = nc())); 22 if(IOerror) return; 23 for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0'); 24 } 25 #undef BUF_SIZE 26 }; 27 using namespace IO;