My头文件(4)

发布时间 2023-09-28 23:25:26作者: vectorStar

自定义头文件"almighty.hpp"

持续更新

almighty.h内部内容:

#ifndef _ALMIGHTY_
#define _ALMIGHTY_

#include<bits/stdc++.h>
using namespace std;

#define sd signed
#define ud unsigned
#define ct const
#define sc static
typedef int i4;
typedef long long i8;
typedef float f4;
typedef double f8;
typedef void vd;
typedef bool bl;
typedef char cr;
typedef string STR;

#define TE true
#define FE false

#define CI cin
#define CO cout
#define EL endl
#define Sf scanf
#define Pf printf
#define Gc getchar
#define Pc putchar
#define QIO_C98 ios::sync_with_stdio(FE), CI.tie(FE), CO.tie(FE);
#define QIO_C11 ios::sync_with_stdio(FE), CI.tie(nullptr), CO.tie(nullptr);

#define Fr for
#define Up(a, b, c, d) Fr (i8 a = b; a <= c; a += d)
#define Dn(a, b, c, d) Fr (i8 a = b; a >= c; a -= d)

vd read(i4&);
i4 Abs(i4);
i4 lowbit(i4);
i4 countbit(i4);
i4 qpow(i4, i4, ct i4);
i4 inv(i4, i4);
i4 gcd(i4, i4);
i4 qgcd(i4, i4);
i4 exgcd(i4, i4, i4&, i4&);
vd Swap(i4&, i4&);

template<class T> vd cin_arr(T[], i4, i4);
template<class T> vd cout_arr(T[], i4, i4, cr);

#endif

almighty.hpp实现:

#include"almighty.h"

vd read(i4 &num) {
	i4 sgn = 0;
	cr ch = Gc();
	while (~ch && !isdigit(ch)) sgn |= ch == '-', ch = Gc();
	while (~ch && isdigit(ch)) num = (num << 1) + (num << 3) + (ch ^ 48), ch = Gc();
	if (sgn) num = -num;
}
i4 Abs(i4 x) {
	i4 a = x >> 31;
	return (x ^ a) - a;
}
i4 lowbit(i4 x) {
	return x & (-x);
}
i4 countbit(i4 x) {
	i4 count = 0;
	while (x) {
		x = x & x - 1;
		count ++;
	}
	return count;
}
i4 qpow(i4 a, i4 b, ct i4 p) {
	i4 res = 1;
	for (; b; b >>= 1ll, a = (i8)a * a % p)
		if (b & 1)
			res = (i8)res * a % p;
	return res;
}
i4 inv(i4 n, i4 p) {
	return qpow(n, p - 2, p);
}
i4 gcd(i4 a, i4 b) {
	return !b ? a : gcd(b, a % b);
}
i4 qgcd(i4 a, i4 b) {
	i4 x = __builtin_ctz(a), y = __builtin_ctz(b), z = min(x, y), k;
	b >>= y;
	while (a) {
		a >>= x;
		k = b - a;
		x = __builtin_ctz(k);
		if (a < b) b = a;
		a = k < 0 ? -k : k;
	}
	return b << z;
}
i4 exgcd(i4 a, i4 b, i4 &x, i4 &y) {
	if (!b) {
		x = 1, y = 0;
		return a;
	}
	i4 d = exgcd(b, a % b, x, y), t = x;
	x = y, y = t - (a / b) * y;
	return d;
}
vd Swap(i4 &a, i4 &b) {
	a ^= b, b ^= a, a ^= b;
}

template<class T>
vd cin_arr(T arr[], i4 first, i4 size) {
	Up(i, 0, size - 1, 1) cin >> arr[i];
}
template<class T>
vd cout_arr(T arr[], i4 first, i4 size, cr _and_) {
	Up(i, 0, size - 1, 1) cout << arr[i], Pc(cr);
}