Update include.hh
Signed-off-by: subcrip <contact@subc.rip>
This commit is contained in:
parent
988a69a740
commit
6e6d8fd24e
25
include.hh
25
include.hh
|
@ -381,17 +381,42 @@ template <ll mdl> struct MLL {
|
||||||
void operator/=(const MLL& rhs) { val = (*this / rhs).val; }
|
void operator/=(const MLL& rhs) { val = (*this / rhs).val; }
|
||||||
void operator%=(const MLL& rhs) { val = (*this % rhs).val; }
|
void operator%=(const MLL& rhs) { val = (*this % rhs).val; }
|
||||||
};
|
};
|
||||||
|
struct MLLd {
|
||||||
|
ll val, mdl;
|
||||||
|
MLLd(ll mdl, ll v = 0) : mdl(mdl), val(mod(v, mdl)) {}
|
||||||
|
MLLd(const MLLd& other) : val(other.val) {}
|
||||||
|
friend MLLd operator+(const MLLd& lhs, const MLLd& rhs) { return mod(lhs.val + rhs.val, mdl); }
|
||||||
|
friend MLLd operator-(const MLLd& lhs, const MLLd& rhs) { return mod(lhs.val - rhs.val, mdl); }
|
||||||
|
friend MLLd operator*(const MLLd& lhs, const MLLd& rhs) { return mod(lhs.val * rhs.val, mdl); }
|
||||||
|
friend MLLd operator/(const MLLd& lhs, const MLLd& rhs) { return mod(lhs.val * mod(inverse(rhs.val, mdl), mdl), mdl); }
|
||||||
|
friend MLLd operator%(const MLLd& lhs, const MLLd& rhs) { return mod(lhs.val - (lhs / rhs).val, mdl); }
|
||||||
|
friend bool operator==(const MLLd& lhs, const MLLd& rhs) { return lhs.val == rhs.val; }
|
||||||
|
friend bool operator!=(const MLLd& lhs, const MLLd& rhs) { return lhs.val != rhs.val; }
|
||||||
|
void operator+=(const MLLd& rhs) { val = (*this + rhs).val; }
|
||||||
|
void operator-=(const MLLd& rhs) { val = (*this - rhs).val; }
|
||||||
|
void operator*=(const MLLd& rhs) { val = (*this * rhs).val; }
|
||||||
|
void operator/=(const MLLd& rhs) { val = (*this / rhs).val; }
|
||||||
|
void operator%=(const MLLd& rhs) { val = (*this % rhs).val; }
|
||||||
|
};
|
||||||
|
|
||||||
template <ll mdl>
|
template <ll mdl>
|
||||||
ostream& operator<<(ostream& out, const MLL<mdl>& num) {
|
ostream& operator<<(ostream& out, const MLL<mdl>& num) {
|
||||||
return out << num.val;
|
return out << num.val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, const MLLd& num) {
|
||||||
|
return out << num.val;
|
||||||
|
}
|
||||||
|
|
||||||
template <ll mdl>
|
template <ll mdl>
|
||||||
istream& operator>>(istream& in, MLL<mdl>& num) {
|
istream& operator>>(istream& in, MLL<mdl>& num) {
|
||||||
return in >> num.val;
|
return in >> num.val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
istream& operator>>(istream& in, MLLd& num) {
|
||||||
|
return in >> num.val;
|
||||||
|
}
|
||||||
|
|
||||||
// miscancellous
|
// miscancellous
|
||||||
template <typename Func, typename RandomIt> void sort_by_key(RandomIt first, RandomIt last, Func extractor) {
|
template <typename Func, typename RandomIt> void sort_by_key(RandomIt first, RandomIt last, Func extractor) {
|
||||||
std::sort(first, last, [&] (auto&& a, auto&& b) { return std::less<>()(extractor(a), extractor(b)); });
|
std::sort(first, last, [&] (auto&& a, auto&& b) { return std::less<>()(extractor(a), extractor(b)); });
|
||||||
|
|
Loading…
Reference in New Issue