标签:const Mess res rhs 算法 operator return Mint 杂项
Mess 杂项算法
Q_read/Q_write
inline int qr(){
int x = 0, f = 1; char c = getchar();
while(!isdigit(c)) {
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return x * f;
}
inline void qw(int a) {
if(a < 0) putchar('-'), a = -a;
if(a > 9) qw(a / 10);
putchar((a % 10) ^ 48);
}
DEBUG
#define dbg(x) cerr << #x << "=" << x << '\n'
template<class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template<class t>
ostream &operator<<(ostream &os, const vector<t> &v) {
os << "[" << (*v.begin());
for (int i = 1;i < v.size();i++) os << ", " << v[i];
return os << "]";
}
Mint
constexpr int P = 1000000007;
using ll = long long;
// assume -P <= x < 2P
int norm(int x) {if(x < 0)x += P;if (x >= P)x -= P;return x;}
template<class T>T power(T a, int b){T res = 1;for (; b; b /= 2, a *= a)if (b & 1)res *= a;return res;}
struct Mint {
int x;Mint(int x = 0) : x(norm(x)){}
int val() const {return x;}
Mint operator-() const {return Mint(norm(P - x));}
Mint inv() const {assert(x != 0);return power(*this, P - 2);}
Mint &operator*=(const Mint &rhs) { x = ll(x) * rhs.x % P; return *this;}
Mint &operator+=(const Mint &rhs) { x = norm(x + rhs.x); return *this;}
Mint &operator-=(const Mint &rhs) { x = norm(x - rhs.x); return *this;}
Mint &operator/=(const Mint &rhs) {return *this *= rhs.inv();}
friend Mint operator*(const Mint &lhs, const Mint &rhs) {Mint res = lhs; res *= rhs; return res;}
friend Mint operator+(const Mint &lhs, const Mint &rhs) {Mint res = lhs; res += rhs; return res;}
friend Mint operator-(const Mint &lhs, const Mint &rhs) {Mint res = lhs; res -= rhs; return res;}
friend Mint operator/(const Mint &lhs, const Mint &rhs) {Mint res = lhs; res /= rhs; return res;}
};
Unordered_map/set Hash
struct haha {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
Random
随机数生成
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
随机打乱
random_shuffle(x.begin(), x.end());
标签:const,Mess,res,rhs,算法,operator,return,Mint,杂项 来源: https://blog.csdn.net/u014711890/article/details/120841953
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。