跳到正文

个人记录

无敌快读

TMLY114514约 5 分钟
原文
文章信息与版本

文章信息

发布
2024年6月1日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 5 分钟

版本

  1. v1当前
C++
namespace IO{
#define ll long long
#define ischar(ch) (32<ch&&ch<127)
#define SIZE 1<<18
	char ibuf[SIZE],*is=ibuf,*it=ibuf;
#define getchar() (is==it&&(it=(is=ibuf)+fread(ibuf,1,SIZE,stdin),is==it)?EOF:*is++)
	template<typename Type>
	inline void read(Type &a){
		Type x=0;int y=0,ch=getchar();
		while(!isdigit(ch)&&(ch^EOF))y|=(ch=='-'),ch=getchar();
		while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
		a=y?-x:x;
	}
	inline void read(char &a){
		int ch=getchar();
		while(!ischar(ch)&&(ch^EOF))ch=getchar();
		a=ch;
	}
	inline void read(string &a){
		a="";char ch;
		while(!ischar(ch)&&(ch^EOF))ch=getchar();
		while(ischar(ch))a+=ch,ch=getchar();
	}
	inline void read(short &a){
		int ch=getchar();
		while(!isdigit(ch)&&(ch^EOF))ch=getchar();
		a=(ch^48);
	}
	template<typename Type>
	inline void read(Type a[]){
		Type *pos=a;
		int ch=getchar();
		while(!ischar(ch)&&(ch^EOF))ch=getchar();
		while(ischar(ch))*pos++=ch,ch=getchar();
		*pos=0;
	}
	inline void read(double &a){
		int zh=0,w=0,ch=getchar();
		double xi=0.0,x=1.0;
		while (!isdigit(ch)&&(ch^EOF))w|=ch=='-',ch=getchar();
		while(isdigit(ch))zh=(zh<<1)+(zh<<3)+(ch^48),ch=getchar();
		if(ch^'.')return void(a=w?-zh:zh);
		ch=getchar();
		while(isdigit(ch))x*=10.0,xi+=(ch^48)*1.0/x,ch=getchar();
		a=w?-zh-xi:zh+xi;
	}
	template<typename Type,typename ...Args>
	inline void read(Type &a,Args &...as){read(a);read(as...);}
	char obuf[SIZE],*op=obuf;
	inline void putch(const char &c){
		if(op-obuf==SIZE)fwrite(obuf,1,op-obuf,stdout),op=obuf;
		*op++=c;
	}
	template<typename Type>
	inline void write(Type x){
		if(x<0)putch('-'),x=-x;
		static int s[35],top;top=0;
		do s[top++]=x%10,x/=10;
		while(x);
		while(top)putch(s[--top]+'0');
	}
	int precision;
	inline void write(double x){
		ll n=1,base=10,k=precision;
		while(k)n=(k&1)?n*base:n,base*=base,k>>=1;
		x=round(x*n)/n;
		if(!x){
			putch('0'),putch('.');
			for(int i=1;i<=precision;++i)putch('0');
			return;
		}
		if(x<0)putch('-'),x=-x;
		ll y=(ll)round(x*n)%n;x=(ll)x;
		write((ll)x);putch('.');
		int s[35],top=0;
		for(;top<precision;y/=10)s[++top]=y%10;
		while(top)putch(s[top--]+'0');
	}
	inline void write(char ch){putch(ch);}
	inline void write(const char* s){for(int i=0;i<strlen(s);++i)putch(s[i]);}
	inline void write(string s){for(int i=0;i<s.size();++i)putch(s[i]);}
	template<typename Type,typename ...Args>
	inline void write(Type a,Args ...as){write(a);write(as...);}
	inline void oclear(){fwrite(obuf,1,op-obuf,stdout);}
#undef SIZE
#undef ischar
}
原文