相对全的fastio

发布时间 2023-11-02 21:26:59作者: 沼中蒻杨
struct FastIO{
	static const int S=1048576;
	char buf[S],*pL,*pR;int stk[20],Top;
	#define Clear() (fwrite(buf,1,Top,stdout),Top=0)
	#define gc() ( pL==pR &&( pR=(pL=buf)+fread(buf,1,S,stdin),pL==pR )?EOF:*pL++)
	#define pc(ch) ( ( (Top==S)&&(Clear(),1) ) , buf[Top++]=(ch) )
	~FastIO(){Clear();}
	template<typename T>FastIO& operator >> (T&_t){
		_t=0;char ch=gc();bool fg=0;while(ch<'0'||ch>'9'){fg=(ch=='-');ch=gc();}
		while(ch>='0'&&ch<='9'){_t=(_t<<1)+(_t<<3)+(ch&15);ch=gc();}(fg?_t=-_t:0);return *this;
	}
	FastIO& operator >> (char&ch)
	{while(ch=gc(),(ch==' '||ch=='\n'));return *this;}
	FastIO& operator >> (char* _s)
	{for(char ch=gc();ch!='\n'&&ch!=' '&&ch!=EOF;ch=gc())*_s++=ch; return *this;}
	FastIO& getline(char *_s,const char &ed='\n')
	{for(char ch=gc();ch!=ed&&ch!=EOF;ch=gc())*_s++=ch; return *this;}
	FastIO& operator >> (std::string &_s)
	{_s.clear();for(char ch=gc();ch!=' '&&ch!='\n'&&ch!=EOF;ch=gc())_s.push_back(ch);return *this;}
	FastIO& getline(std::string &_s,const char &ed='\n')
	{_s.clear();for(char ch=gc();ch!=ed&&ch!=EOF;ch=gc())_s.push_back(ch);return *this;}
	template<typename T>FastIO& operator << (T _t){
		if(_t<0){pc('-');_t=-_t;}do{stk[++(*stk)]=_t%10;_t/=10;}while(_t);
		while(*stk) pc('0'+stk[(*stk)--]);return *this;
	}
	FastIO& endl(){pc('\n');Clear();}
	FastIO& operator << (const char &ch){pc(ch);return *this;}
	FastIO& operator << (char *_s){while(*_s)pc(*_s++);return *this;}
	FastIO& operator << (const char *_s)
	{int p=0;while(*(_s+p))pc(*(_s+(p++)));return *this;}
	FastIO& operator << (const std::string &str){
		int ed=str.size(),p=0;const char *_s=str.c_str();
		while(p<ed)pc(*(_s+(p++)));return *this;
	}
	#undef Clear
	#undef gc
	#undef pc
}fin,fout;
#define cin fin
#define cout fout