#ifndef ONLINE_JUDGE freopen... #endif
std::ios::sync_with_stdio(false);
# pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wattributes" # pragma GCC diagnostic ignored "-Wpragmas" # pragma GCC diagnostic error "-std=c++11" # pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-falign-functions,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3) # pragma GCC target("avx","sse2") # 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("-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("-falign-functions") # 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("inline-functions-called-once") # pragma GCC optimize("-fdelete-null-pointer-checks") # pragma GCC diagnostic pop #define Finline __inline__ __attribute__ ((always_inline)) Finline char get_char(){ static char READBUF[200000001], *READP1 = READBUF, *READP2 = READBUF + fread(READBUF, 1, 200000000, stdin); return READP1 == READP2 ? EOF : *READP1 ++; }
#pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline")
inline int min (int a, int b) { int c = (a - b) >> 31; return a ^ c | b ^ ~c; }
#define re register #define il inline
在自定义函数前加上inline,在循环内加上register,可提升少许运行速度,例如:
il int find(int x){ return fa[x] == x ? x : fa[x] = find(fa[x]); }
for (re int i = a;i <= b;++ i)
freopen:
#define fin(a) freopen (#a".in","r",stdin) #define fout(a) freopen (#a".out","w",stdout)
循环:
#define rep(i,a,b) for (re int i = a;i <= b;++ i) #define Rep(i,a,b) for (re int i = a;i < b;++ i) #define drep(i,a,b) for (re int i = a;i >= b;-- i)
il ll read() { ll x = 0; char ch = 0; while(!isdigit(ch)) { ch = getchar(); } while(isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x; } il void write(ll x) { if(x > 9) { write(x / 10); } putchar(x % 10 + '0'); }
il ll Pow(ll a,ll b) { ll ans = 1; while(b) { if(b & 1) ans = ans * a % MOD; a = a * a % MOD; b >>= 1; } return ans % MOD; }
il ll C(ll n,ll m) { if (m > n) return 0; if (m > n - m) m = n - m; ll s1 = 1,s2 = 1; Rep(i,0,m) { s1 = s1 * (n - i) % MOD; s2 = s2 * (i + 1) % MOD; } return s1 * Pow(s2,MOD - 2) % MOD; }
il ll Lucas (int n,int m) { if (!m) return 1; return C(n % MOD,m % MOD) * Lucas(n / MOD,m / MOD) % MOD; }