快读快写
C++namespace FastIO{
#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc _getchar_nolock
#define pc _putchar_nolock
#endif
inline bool blank(char x){
return !(x^32)||!(x^10)||!(x^13)||!(x^9);
}
template<typename Tp>
inline void read(Tp &x){
x=0;
bool f=1;
char ch=gc();
for(;!isdigit(ch);ch=gc())
if(ch=='-') f=0;
for(;isdigit(ch);ch=gc())
x=(x<<1)+(x<<3)+(ch^48);
x=(f?x:~x+1);
}
inline void read(double &x){
x=0;
bool f=1;
char ch=gc();
for(;!isdigit(ch);ch=gc())
if(ch=='-') f=0;
for(;isdigit(ch);ch=gc())
x=x*10+(ch^48);
if(ch!='.') return x=(f?x:-x),void();
ch=gc();
for(double y=0.1;isdigit(ch);ch=gc(),y/=10)
x+=y*(ch^48);
x=(f?x:-x);
}
inline void read(char &x){
for(x=gc();blank(x)&&(x^-1);x=gc());
}
inline void read(char *x){
char ch=gc();
for(;blank(ch)&&(ch^-1);ch=gc());
for(;!blank(ch)&&(ch^-1);ch=gc())
*x++=ch;
*x=0;
}
inline void read(string &x){
x="";
char ch=gc();
for(;blank(ch)&&(ch^-1);ch=gc());
for(;!blank(ch)&&(ch^-1);ch=gc())
x+=ch;
}
template<typename T,typename ...Tp>
inline void read(T &x,Tp &...y){read(x),read(y...);}
template<typename Tp>
inline void write(Tp x){
if(!x) return pc(48),void();
if(x<0) pc('-'),x=~x+1;
int len=0; char tmp[64];
for(;x;x/=10) tmp[++len]=x%10+48;
while(len) pc(tmp[len--]);
}
inline void write(const char x){pc(x);}
inline void write(const bool x){pc(x?49:48);}
inline void write(char *x){fputs(x,stdout);}
inline void write(const char *x){fputs(x,stdout);}
inline void write(const string &x){fputs(x.c_str(),stdout);}
template<typename T,typename ...Tp>
inline void write(T x,Tp ...y){write(x),write(y...);}
}
using namespace FastIO;
需要 cmath & iomanip
C++#define inl_force __attribute__((always_inline)) inline
using namespace std;
namespace FastIO{
#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc _getchar_nolock
#define pc _putchar_nolock
#endif
inl_force bool blank(char x){
return !(x^32)||!(x^10)||!(x^13)||!(x^9);
}
template<typename Tp>
inl_force void read(Tp& x){
x=0;
bool f=true;
char ch=gc();
for(;!isdigit(ch);ch=gc())
if(ch=='-') f=false;
for(;isdigit(ch);ch=gc())
x=(x<<1)+(x<<3)+(ch^48);
x=(f?x:~x+1);
}
inl_force void read(double& x){
x=0.0;
bool f=true;
char ch=gc();
for(;!isdigit(ch);ch=gc())
if(ch=='-') f=false;
for(;isdigit(ch);ch=gc())
x=(x*10)+(ch^48);
if(ch!='.') x=(f?x:-x);
ch=gc();
for(double y=0.1;isdigit(ch);y/=10,ch=gc())
x+=y*(ch^48);
x=(f?x:-x);
}
inl_force void read(char& x){
for(x=gc();blank(x)&&(x^-1);x=gc());
}
inl_force void read(char* x){
char ch=gc();
for(;blank(ch)&&(ch^-1);ch=gc());
for(;!blank(ch)&&(ch^-1);ch=gc())
*x++=ch;
*x=0;
}
inl_force void read(string& x){
x="";
char ch=gc();
for(;blank(ch)&&(ch^-1);ch=gc());
for(;!blank(ch)&&(ch^-1);ch=gc())
x+=ch;
}
template<typename T,typename... Tp>
inl_force void read(T& x,Tp&... y){read(x),read(y...);}
template<typename Tp>
inl_force void write(Tp x){
if(!x) return pc(48),void();
if(x<0) pc('-'),x=~x+1;
int len=0; char tmp[64];
for(;x;x/=10) tmp[++len]=x%10^48;
while(len) pc(tmp[len--]);
}
inl_force void write(double x){cout<<x;}
inl_force void write(const pair<int,double> x){
cout<<fixed<<setprecision(x.first)<<x.second;
}
inl_force void write(const char x){pc(x);}
inl_force void write(const bool x){pc(x?49:48);}
inl_force void write(char* x){fputs(x,stdout);}
inl_force void write(const char* x){fputs(x,stdout);}
inl_force void write(const string& x){
fputs(x.c_str(),stdout);
}
template<typename T,typename... Tp>
inl_force void write(T x,Tp... y){write(x),write(y...);}
}
using namespace FastIO;