卡常剪贴板

编译命令优化

放在代码头部,比赛不可用。

手动O2优化

#pragma GCC optimize("O2")

手动O3优化

#pragma GCC optimize("O3")

三行

#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")

火车头

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

FastIO

普通快读

namespace FastIO
{
char c;
bool sign;
template<class T>
inline void read(T &x)
{
	x=0;
	sign=false;
	for(c=getchar();c<'0'||c>'9';c=getchar()) 
		if(c=='-') 
			sign=true;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	if(sign) x=~x+1;
 	return;
}
}
using FastIO::read;

不建议手写快输,可能比 printf 都慢。

快读

1号。

namespace FastIO
{
	const int _SIZE = (1 << 21) + 1;
	char ibuf[_SIZE],*iS,*iT;
	inline char getc()
	{
		if(iS==iT) 
			iS=ibuf,iT=iS+fread(ibuf,1,_SIZE,stdin);
		return (iS == iT ? EOF : *iS++);
	}
	template <class T>
	inline void read(T &x) 
	{
		x=0;
		register char c;
		register bool sign=false;
	    for (c=getc();c<'0' || c>'9';c=getc())
	        if (c=='-') sign=true;
	    for (;c>='0' && c<='9';c=getc()) 
			x=(x<<1)+(x<<3)+(c&15);
		if(sign) x=~x+1;
	}
}
using FastIO::getc;
using FastIO::read;

2号。

namespace FastIO
{
	const int _SIZE = (1 << 21) + 1;
	char ibuf[_SIZE],*iS,*iT;
	char obuf[_SIZE],*oS=obuf,*oT=obuf+_SIZE-1;
	
	inline char getc()
	{
		if(iS==iT) 
			iS=ibuf,iT=iS+fread(ibuf,1,_SIZE,stdin);
		return (iS == iT ? EOF : *iS++);
	}
	
	template <class T>
	inline void read(T &x) 
	{
		x=0;
		register char c;
		register bool sign=false;
	    for (c=getc();c<'0' || c>'9';c=getc())
	        if (c=='-') sign=true;
	    for (;c>='0' && c<='9';c=getc()) 
			x=(x<<1)+(x<<3)+(c&15);
		if(sign) x=~x+1;
	}
	
	inline void flush() { fwrite(obuf,1,oS-obuf,stdout); oS=obuf; }
	inline void putc(register char x) { *oS++=x; if(oS==oT) flush(); }
	
	template <class T>
	inline void write(T x) {
		static char qu[50];
		
		register int qr;
	    if (!x) return putc('0');
	    if (x<0) putc('-'),x=~x+1;
	    for(qr=1;x;qr++,x/=10) qu[qr]=x%10+'0';
	    for(qr--;qr>=1;qr--) putc(qu[qr]);
	}

	struct Flusher_ 
	{
 	   ~Flusher_() { flush(); }
	}io_flusher_;
}
using FastIO::getc;
using FastIO::putc;
using FastIO::read;
using FastIO::write;
#define enter FastIO::putc('\n')

注意不可以与其他读入方式混用。

其他

适当使用关键字

register 
inline
#define

参考文献:

posted @ 2020-12-01 13:21  cjlworld  阅读(170)  评论(0编辑  收藏  举报