My头文件(9)

发布时间 2023-10-15 10:11:32作者: vectorStar

自定义头文件"almighty.hpp"

持续更新

almighty.h内部内容

#ifndef _ALMIGHTY_
#define _ALMIGHTY_

#include<bits/stdc++.h>

#define dnp Random_Numbers_Moonspace
#define dsm Data_Structure_Moonspace

using namespace std;

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

#define ope operator

#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)

#define pi 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019
#define e 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901157383418793070215408914993488416750924476146066808226480016847741185374234544243710753907774499206955170276183860626133138458300075204493382656029760673711320070932870912744374704723069697720931014169283681902551510865746377211125238978442505695369677078544996996794686445490598793163688923009879312773617821542499922957635148220826989519366803318252886939849646510582093923982948879332036250944311730123819706841614039701983767932068328237646480429531180232878250981945581530175671736133206981125099618188159304169035159888851934580727386673858942287922849989208680582574927961048419844436346324496848756023362482704197862320900216099023530436994184914631409343173814364054625315209618369088870701676839642437814059271456354906130310720851038375051011574770417189861068739696552126715468895703503
#define Cpi 3.14159265358979
#define Ce 2.71828182845904

#define error return cerr << "Error" << endl, -1;

vd read(i4&);
i4 Abs(i4);
i4 lowbit(i4);
i4 countbit(i4);
i4 qpow(i4, i4, ct i4);
i4 inv(i4, i4);
template<class T>
T gcd(T, T);
template<class T>
T qgcd(T, T);
i4 exgcd(i4, i4, i4&, i4&);
vd Swap(i4&, i4&);

namespace dnp {
	i4 random_int(i4, i4);
	i8 random_long(i8, i8);
	f8 random_double(f8, f8);
	vd kill_random();
	vd random_int_vector(vector<i4> &, i4, i4, i4);
	vd random_double_vector(vector<f8> &, i4, f8, f8);
}

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

namespace dsm {
	template<class Vec_name>
	class Vec {
		public:
			i4 head, tail;
			vector<Vec_name> Vec_array;
			Vec_name ope[](i4);
			//i4 ope==(ct Vec&) ct;
			vd fill_Vec(Vec_name);
			vd fill_Vec(i4, i4, Vec_name);
			Vec(i4, Vec_name);
			Vec(i4, i4, Vec_name);
			i4 PUSH_front(Vec_name);
			i4 POP_front();
			i4 PUSH_back(Vec_name);
			i4 POP_back();
			i4 Size();
			vd sort_Vec(bl, bl);
			vd sort_Vec(i4, i4, bl, bl);
			vd cin_Vec();
			vd cin_Vec(i4, i4);
			vd cout_Vec(cr);
			vd cout_Vec(i4, i4, cr);
	};
}
class largeint {
	private:
		vector<i2> num;
		bl sgn;
	public:
		largeint();
		largeint(STR);
		template<typename T>
		largeint(T);
		template<typename T>
		largeint(vector<T>&);
		bl sign();
		bl resign(bl);
		i4 length();
		i4 resize(i4, i4);
		i4 extend(i4, i4);
		vd swap(i4, i4);
		vd swap(largeint&);
		vd fill(i4, i4, i4);
		vd update();
		vd clear();
		vd input();
		vd output();
		i2 ope[](i4);
		vd ope=(vector<i2>&);
		vd ope=(ct largeint&);
		bl ope<(largeint&);
		bl ope>(largeint&);
		bl ope==(largeint&);
		largeint abs();
		largeint ope+(largeint&);
};
#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);
}
template<class T>
T gcd(T a, T b) {
	return !b ? a : gcd(b, a % b);
}
template<class T>
T qgcd(T a, T b) {
	T 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;
}

default_random_engine d(time(0));
i4 dnp::random_int(i4 l, i4 r) {
	uniform_int_distribution<> u(l, r);
	return u(d);
}
i8 dnp::random_long(i8 l, i8 r) {
	uniform_int_distribution<i8> u(l, r);
	return u(d);
}
f8 dnp::random_double(f8 l, f8 r) {
	uniform_real_distribution<> u(l, r);
	return u(d);
}
vd dnp::kill_random() {
	random_int(0, 1);
	random_double(0.0, 1.0);
}
vd dnp::random_int_vector(vector<i4> &rand_vec, i4 num, i4 l, i4 r) {
	rand_vec.clear();
	Up(i, 1, num, 1) rand_vec.push_back(random_int(l, r));
}
vd dnp::random_double_vector(vector<f8> &rand_vec, i4 num, f8 l, f8 r) {
	rand_vec.clear();
	Up(i, 1, num, 1) rand_vec.push_back(random_double(l, r));
}

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

template<class Vec_name> Vec_name dsm::Vec<Vec_name>::ope[](i4 index) {
	return this -> Vec_array.at(index);
}
template<class Vec_name> vd dsm::Vec<Vec_name>::fill_Vec(Vec_name content) {
	//if (Vec_array.size() <= tail - head) Vec_array.resize(tail + 5);
	Up(i, this -> head, this -> tail, 1) this -> Vec_array.at(i) = content;
}
template<class Vec_name> vd dsm::Vec<Vec_name>::fill_Vec(i4 l, i4 r, Vec_name content) {
	//if (Vec_array.size() <= tail - head) Vec_array.resize(tail + 5);
	l = max(0, l), r = min(this -> tail + 2, r);
	Up(i, l, r, 1) this -> Vec_array.at(i) = content;
}
template<class Vec_name> dsm::Vec<Vec_name>::Vec(i4 r, Vec_name content) {
	this -> head = 0, this -> tail = max(1, r);
	this -> Vec_array.resize(tail + 10);
	fill_Vec(0, this -> tail, 0);
	fill_Vec(content);
}
template<class Vec_name> dsm::Vec<Vec_name>::Vec(i4 l, i4 r, Vec_name content) {
	this -> head = max(min(l, r), 0), this -> tail = max(max(l, r), 1);
	this -> Vec_array.resize(this -> tail + 10);
	fill_Vec(0, this -> tail, 0);
	fill_Vec(content);
}
template<class Vec_name> i4 dsm::Vec<Vec_name>::PUSH_front(Vec_name push) {
	if (!this -> head) error
	this -> Vec_array[-- this -> head] = push;
	return 1;
}
template<class Vec_name> i4 dsm::Vec<Vec_name>::POP_front() {
	if (this -> head >= this -> tail) error
	++ this -> head;
	return 1;
}
template<class Vec_name> i4 dsm::Vec<Vec_name>::PUSH_back(Vec_name push) {
	if (this -> tail >= this -> Vec_array.size()) this -> Vec_array.resize(this -> tail + 10, 0);
	this -> Vec_array[++ this -> tail] = push;
	return 1;
}
template<class Vec_name> i4 dsm::Vec<Vec_name>::POP_back() {
	if (this -> tail <= this -> head) error
	this -> tail --;
	return 1;
}
template<class Vec_name> i4 dsm::Vec<Vec_name>::Size() {
	if (this -> head > this -> tail) error
	return this -> tail - this -> head + 1;
}
template<class Vec_name> vd dsm::Vec<Vec_name>::sort_Vec(bl way, bl order) {
	if (way)
		if (order) sort(this -> Vec_array.begin() + this -> head, this -> Vec_array.begin() + this -> tail);
		else sort(this -> Vec_array.begin() + this -> head, this -> Vec_array.begin() + this -> tail, greater<Vec_name>());
	else
		if (order) table_sort(this -> Vec_array.begin() + this -> head, this -> Vec_array.begin() + this -> tail);
		else table_sort(this -> Vec_array.begin() + this -> head, this -> Vec_array.begin() + this -> tail, greater<Vec_name>());
}
template<class Vec_name> vd dsm::Vec<Vec_name>::sort_Vec(i4 l, i4 r, bl way, bl order) {
	if (way)
		if (order) sort(this -> Vec_array.begin() + l, this -> Vec_array.begin() + r);
		else sort(this -> Vec_array.begin() + l, this -> Vec_array.begin() + r, greater<Vec_name>());
	else
		if (order) table_sort(this -> Vec_array.begin() + l, this -> Vec_array.begin() + r);
		else table_sort(this -> Vec_array.begin() + l, this -> Vec_array.begin() + r, greater<Vec_name>());
}
template<class Vec_name> vd dsm::Vec<Vec_name>::cin_Vec() {
	Up(i, this -> head, this -> tail, 1) CI >> this -> Vec_array.at(i);
}
template<class Vec_name> vd dsm::Vec<Vec_name>::cin_Vec(i4 l, i4 r) {
	l = max(0, min(l, r)), r = max(0, max(l, r));
	Up(i, l, r, 1) CI >> this -> Vec_array.at(i);
}
template<class Vec_name> vd dsm::Vec<Vec_name>::cout_Vec(cr _and_) {
	Up(i, this -> head, this -> tail, 1) CO << this -> Vec_array.at(i) << _and_;
}
template<class Vec_name> vd dsm::Vec<Vec_name>::cout_Vec(i4 l, i4 r, cr _and_) {
	l = max(0, min(l, r)), r = max(0, max(l, r));
	Up(i, l, r, 1) CO << this -> Vec_array.at(i) << _and_;
}

largeint::largeint () {
	this -> num.push_back(0);
}
largeint::largeint(string s) {
	for (i4 i = s.size() - 1; ~i; i --)
		this -> num.push_back(s[i] ^ 48);
}
template<typename T>
largeint::largeint(T num = 0) {
	if (!num) this -> num.push_back(0);
	while (num) {
		this -> num.push_back(num % 10);
		num /= 10;
	}
}
template<typename T>
largeint::largeint(vector<T> &num) {
	this -> num = num;
}
bl largeint::sign() {
	return this -> sgn;
}
bl largeint::resign(bl sg) {
	bl res = this -> sgn;
	this -> sgn = sg;
	return res;
}
i4 largeint::length() {
	return num.size();
}
i4 largeint::resize(i4 len, i4 elememt = 0) {
	i4 res = this -> length();
	this -> num.resize(len, elememt);
	return res;
}
i4 largeint::extend(i4 len, i4 elememt = 0) {
	ct i4 Len = this -> length();
	if (-len > Len) len = -Len;
	return this -> resize(Len + len, elememt);
}
vd largeint::swap(i4 iax, i4 ibx) {
	this -> num[iax] ^= this -> num[ibx], this -> num[ibx] ^= this -> num[iax], this -> num[iax] ^= this -> num[ibx];
}
vd largeint::swap(largeint& number) {
	largeint cnt = *this;
	*this = number, number = cnt;
}
vd largeint::fill(i4 l = 0, i4 r = *this.length(), i4 element) {
	Up(i, l, r, 1) num[i] = element;
}
vd largeint::update() {
	while (!num.empty() && !num.back()) num.pop_back();
	if (num.empty()) num.push_back(0);
}
vd largeint::clear() {
	vector<i2>().swap(this -> num);
}
vd largeint::input() {
	clear();
	this -> sgn = 0;
	char c = getchar();
	while (~c && !isdigit(c)) this -> sgn |= c == '-', c = getchar();
	while (isdigit(c)) {
		this -> num.emplace(this -> num.begin(), c ^ 48);
		c = getchar();
	}
}
vd largeint::output() {
	if (this -> sgn) putchar('-');
	for (i4 i = this -> length() - 1; ~i; i --)
		putchar(num[i] + 48);
}
i2 largeint::ope[](i4 idx) {
	return this -> num[idx];
}
vd largeint::ope=(vector<i2> &vec) {
	this -> num = vec;
}
vd largeint::ope=(const largeint& vec) {
	this -> num = vec.num;
	this -> sgn = vec.sgn;
}
bl largeint::ope<(largeint& vec) {
	if (this -> length() != vec.length())
		return this -> length() < vec.length();
	for (i4 i = this -> length() - 1; ~i; i --)
		if (this -> num[i] != vec[i])
			return this -> num[i] < vec[i];
	return false;
}
bl largeint::ope>(largeint& vec) {
	if (this -> length() != vec.length())
		return this -> length() > vec.length();
	for (i4 i = this -> length() - 1; ~i; i --)
		if (this -> num[i] != vec[i])
			return this -> num[i] > vec[i];
	return false;
}
bl largeint::ope==(largeint& vec) {
	if (this -> length() != vec.length())
		return false;
	for (i4 i = this -> length() - 1; ~i; i --)
		if (this -> num[i] != vec[i])
			return false;
	return true;
}
largeint largeint::abs() {
	largeint res;
	res = this -> num;
	res.sgn = false;
	return res;
}
largeint largeint::ope+(largeint& vec) {
	largeint res_add();
	if (this -> sgn == vec.sign()) res_add.resign(this -> sgn);
	i4 alen = length(), blen = vec.length();
	i4 len = max(alen, blen);
	res_add.resize(len + 2, 0);
	Up(i, 0, len - 1, 1) {
		res_add[i] = *this[i] + vec[i];
		if (i) res_add[i] += res_add[i - 1] / 10,
			res_add[i - 1] %= 10;
	}
	res_add.update();
	return res_add;
}