跳到正文

算法·理论

快读and快写

yi_hr约 11 分钟
原文
文章信息与版本

文章信息

发布
2024年7月18日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 11 分钟

版本

  1. v1当前
C++
namespace Std{
	//char buf[1<<20],*p1,*p2;
	//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
	inline void read128(__int128 &x){
	    bool f=1;x=0;char ch=getchar();
	    while(ch<'0'||ch>'9'){if(ch=='-') f=!f;ch=getchar();}
	    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	    x=(f?x:-x);return;
	}
    inline void write128(__int128 x){
        if(x<0) putchar('-'),x=-x;
        if(x>9) write128(x/10);
        putchar(x%10+'0');return;
    }
	inline void readD(double &x){scanf("%lf",&x);}
	inline void writeD(double x){printf("%lf",x);}
	inline void writeD(double x,int len){printf("%.*lf",len,x);}
	template<typename T>inline void readT(T &x){
	    bool f=1;x=0;char ch=getchar();
	    while(ch<'0'||ch>'9'){if(ch=='-') f=!f;ch=getchar();}
	    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	    x=(f?x:-x);return;
	}
	template<typename T>
	inline void writeT(T x){
	    if(x<0) putchar('-'),x=-x;
	    if(x>9) writeT(x/10);
	    putchar(x%10+'0');return;
	}
	inline void readS(std::string &s){
		char ch=getchar();
		while(ch==' '||ch=='\n') ch=getchar();
		while(ch!=' '&&ch!='\n') s+=ch,ch=getchar();
	}
	inline void readSL(std::string &s){
		char ch=getchar();
		while(ch=='\n') ch=getchar();
		while(ch!='\n') s+=ch,ch=getchar();
	}
	inline void writeS(std::string s){
		int len=s.length();
		for(int i=0;i<len;i++)
			putchar(s[i]);
	}
	inline int readC(char s[]){
		int tot=0;char ch=getchar();
		while(ch==' '||ch=='\n') ch=getchar();
		while(ch!=' '&&ch!='\n') s[tot++]=ch,ch=getchar();
		return tot;
	}
	inline void writeC(char s[],int len){
		for(int i=0;i<len;i++)
			putchar(s[i]);
	}
	inline void readc(char &c){
		c=getchar();
		while(c==' '||c=='\n')
			c=getchar();
	}inline void writec(char c){putchar(c);}
	
	const std::string c="c";
	const std::string i="i";
	const std::string j="j";
	const std::string X="x";
	const std::string y="y";
	const std::string b="b";
	const std::string s="s";
	const std::string Ss="Ss";
	
	template<class T>
	inline void read(T &x) {
		if(typeid(x).name()==i) readT(x);
		else if(typeid(x).name()==j) readT(x);
		else if(typeid(x).name()==X) readT(x);
		else if(typeid(x).name()==y) readT(x);
		if(typeid(x).name()==b){
			int k;readT(k);
			x=(k>0?true:false);
		}else if(typeid(x).name()==s) readT(x);
		else if(typeid(x).name()==c){char ch;readc(ch);x=ch;}
	}
	template<class T,class... Ts>
	inline void read(T &x,Ts&... xx){
		if(typeid(x).name()==i) readT(x);
		else if(typeid(x).name()==j) readT(x);
		else if(typeid(x).name()==X) readT(x);
		else if(typeid(x).name()==y) readT(x);
		if(typeid(x).name()==b){
			int k;readT(k);
			x=(k>0?true:false);
		}else if(typeid(x).name()==s) readT(x);
		else if(typeid(x).name()==c){char ch;readc(ch);x=ch;}
		read(xx...);
	}
	inline void read(std::string &x){readS(x);}
	
	inline void read(char x[]){readC(x);}
	
	inline void read(double &x){readD(x);}
	
	inline void write(double x){writeD(x);}
	
	inline void write(double x,int len){writeD(x,len);}
	
	inline void write(std::string x){writeS(x);}
	
	inline void write(char x[]){writeC(x,strlen(x));}
	
	inline void write(double x,char a){writeD(x);putchar(a);}
	
	inline void write(std::string x,char a){writeS(x);putchar(a);}
	
	inline void write(char x[],char a){writeC(x,strlen(x));putchar(a);}
	
	inline void write(double x,int len,char a){writeD(x,len);putchar(a);}
	
	template<class T>inline void write(T x,char a){
		if(typeid(x).name()==i) writeT(x);
		else if(typeid(x).name()==j) writeT(x);
		else if(typeid(x).name()==X) writeT(x);
		else if(typeid(x).name()==y) writeT(x);
		if(typeid(x).name()==b){
			if(x) writeT(1);
			else writeT(0);
		}else if(typeid(x).name()==s) writeT(x);
		else if(typeid(x).name()==c){writec(x);}
		putchar(a);
	}	
	inline void write(double x,std::string a){writeD(x);writeS(a);}
	
	inline void write(std::string x,std::string a){writeS(x);writeS(a);}
	
	inline void write(char x[],std::string a){writeC(x,strlen(x));writeS(a);}
	
	inline void write(double x,int len,std::string a){writeD(x,len);writeS(a);}
	
	inline void write(char a,std::string s){writec(a);writeS(s);}
	
	template<typename T>inline void write(T x,std::string a){
		if(typeid(x).name()==i) writeT(x);
		else if(typeid(x).name()==j) writeT(x);
		else if(typeid(x).name()==X) writeT(x);
		else if(typeid(x).name()==y) writeT(x);
		if(typeid(x).name()==b){
			if(x) writeT(1);
			else writeT(0);
		}else if(typeid(x).name()==s) writeT(x);
		else if(typeid(x).name()==c){writec(x);}
		writeS(a);
	}
	template<typename T>inline void write(T x){
		if(typeid(x).name()==i) writeT(x);
		else if(typeid(x).name()==j) writeT(x);
		else if(typeid(x).name()==X) writeT(x);
		else if(typeid(x).name()==y) writeT(x);
		if(typeid(x).name()==b){
			if(x) writeT(1);
			else writeT(0);
		}else if(typeid(x).name()==s) writeT(x);
		else if(typeid(x).name()==c) writec(x);
	}
	template<typename T,typename... Ts>
	inline void write(T x,Ts... xx){
		if(typeid(x).name()==i) writeT(x);
		else if(typeid(x).name()==j) writeT(x);
		else if(typeid(x).name()==X) writeT(x);
		else if(typeid(x).name()==y) writeT(x);
		if(typeid(x).name()==b){
			if(x) writeT(1);
			else writeT(0);
		}else if(typeid(x).name()==s) writeT(x);
		else if(typeid(x).name()==c){writec(x);}
		write(xx...);
	}
	inline void put(std::string s){
		int len=s.length();
		for(int i=0;i<len;i++){
			putchar(s[i]);
		}
	}
}
using namespace Std;
原文