char buf[1<<20],*p1,*p2;
inline char gc()
{
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))==p1?0:*p1++;
}template<typename T>
void read(T &x)
{
    char tt;
    bool flag=0;
    while(!isdigit(tt=gc())&&tt!='-');
    tt=='-'?(x=0,flag=1):(x=tt-'0');
    while(isdigit(tt=gc())) x=x*10+tt-'0';
    if(flag) x=-x;
}template<typename T>
void write(T x,bool flag)
{
    if(x<0) putchar('-'),x=-x;
    if(!flag) putchar(x%10+'0');
    if(x>9) write(x/10,1),putchar(x%10+'0');
}原文:https://www.cnblogs.com/KatouKatou/p/9521125.html