常数优化
先看
c++版本以及是否打开优化开关
deque\Rightarrow vector模拟队列- 自写
min、max - 少用
STL - 快读快写、
fread、fwrite - 频繁改变的变量加
register - 访问
a[i]后访问a[i+1]、a[i+2]··· - 数组开奇数(原因不明)
- 循环展开:
for(int i=1;i<=10000;i++)a[i]++;\Rightarrow for(int i=1;i<=10000;i+=4)a[i]++,a[i+1]++,a[i+2]++,a[i+3]++; - 位运算:
x*=(2,4,8,16...)\Rightarrow x<<=(1,2,3,4...)( /=\Rightarrow >>=) x%2\Rightarrow x&1x>y\Rightarrow int: y-x>>31long long: y-x>>63-x\Rightarrow ~x+1swap(x,y)\Rightarrow x^=y^=x^=yabs(x)\Rightarrow (x^(x>>31))-(x>>31)long long: 31\Rightarrow 63
bool\Rightarrow int/ bitsetinlineif(a)b;else c;\Rightarrow a?b:c;if(a)b;\Rightarrow a&&b;;\Rightarrow ,int i=1;\Rightarrow int i(1);i++;\Rightarrow ++i;