- 简单组合数工具
namespace Math {
int qpow(int x, int y)
{
int ans = 1;
while (y)
{
if (y & 1) ans = 1ll * ans * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return ans;
}
int inv(int x) {return qpow(x, mod - 2);}
int fac[N], infac[N];
void init(int n)
{
fac[0] = infac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % mod;
infac[n] = inv(fac[n]); for (int i = n - 1; i; i--) infac[i] = 1ll * infac[i + 1] * (i + 1) % mod;
}
int C(int n, int m) {if (n < 0 || m < 0 || n - m < 0) return 0; return 1ll * fac[n] * infac[m] % mod * infac[n - m] % mod;}
int A(int n, int m) {if (n < 0 || m < 0 || n - m < 0) return 0; return 1ll * fac[n] * infac[n - m] % mod;}
} using namespace Math;-
超级快读
return 0记得改成return flush(), 0。- 快读可以负数,但快写不支持负数,这个不难改,但我实在是太懒了。
char ibuf[1 << 20], *is = ibuf, *it = ibuf;
char obuf[1 << 20], *os = obuf, *ot = obuf + (1 << 20);
#define getchar() is == it && (it = (is = ibuf) + fread(ibuf, 1, 1 << 20, stdin), is == it) ? EOF : *is++
#define flush() (fwrite(obuf, 1, os - obuf, stdout), os = obuf)
#define putchar(ch) *os++ = ch, os == ot ? flush() : 0
inline int read() {char op = getchar(); bool f = 0; int x = 0; while (op < 48 || op > 57) op = getchar(), f |= (op == '-'); while (48 <= op && op <= 57) x = (x << 1) + (x << 3) + (op ^ 48), op = getchar(); return f == 0 ? x : -x;}
inline long long Lread() {char op = getchar(); bool f = 0; long long x = 0; while (op < 48 || op > 57) op = getchar(), f |= (op == '-'); while (48 <= op && op <= 57) x = (x << 1) + (x << 3) + (op ^ 48), op = getchar(); return f == 0 ? x : -x;}
inline void write(long long x) {static int tmp[20], len = -1; do tmp[++len] = x % 10, x /= 10; while (x); while(~len) putchar(tmp[len--] + 48);}- 超级 GCD
inline int gcd(int a, int b) {int az = __builtin_ctz(a), bz = __builtin_ctz(b), z = (az > bz) ? bz : az, t; b >>= bz; while (a) a >>= az, t = a - b, az = __builtin_ctz(t), a = t < 0 ? -t : t, b = a < b ? a : b; return b << z;}- 超级
rand()
inline int rnd() {static int seed = 2333; return seed = (((seed * 666666ll + 20050818) % 998244353) ^ 1000000007) % 1004535809;}