アフィン変換
(math/affine-transformation.hpp)
- View this file on GitHub
- Last update: 2024-05-03 21:06:15+09:00
- Include:
#include "math/affine-transformation.hpp"
Verified with
verify/verify-unit-test/rbst-segment-tree.test.cpp
verify/verify-yosupo-ds/yosupo-deque-operate-all-composite.test.cpp
verify/verify-yosupo-ds/yosupo-dynamic-sequence-range-affine-range-sum-splay.test.cpp
verify/verify-yosupo-ds/yosupo-dynamic-sequence-range-affine-range-sum-treap.test.cpp
verify/verify-yosupo-ds/yosupo-dynamic-sequence-range-affine-range-sum.test.cpp
verify/verify-yosupo-ds/yosupo-dynamic-tree-vertex-set-path-composite.test.cpp
verify/verify-yosupo-ds/yosupo-point-set-range-composite-dynamic-segtree.test.cpp
verify/verify-yosupo-ds/yosupo-point-set-range-composite-rbstseg.test.cpp
verify/verify-yosupo-ds/yosupo-point-set-range-composite-rbstseg2.test.cpp
verify/verify-yosupo-ds/yosupo-range-add-range-sum-linkcuttree.test.cpp
verify/verify-yosupo-ds/yosupo-range-affine-range-sum-dynamic-segtree.test.cpp
verify/verify-yosupo-ds/yosupo-range-affine-range-sum-rbstseg.test.cpp
verify/verify-yosupo-ds/yosupo-range-affine-sqdec.test.cpp
verify/verify-yosupo-ds/yosupo-range-set-range-composite.test.cpp
verify/verify-yosupo-ds/yosupo-vertex-set-path-composite.test.cpp
Code
#pragma once
template <typename mint>
struct Affine {
mint a, b;
constexpr Affine() : a(1), b(0) {}
constexpr Affine(mint _a, mint _b) : a(_a), b(_b) {}
// R(L(x))
friend Affine operator*(const Affine& l, const Affine& r) {
return Affine(l.a * r.a, l.b * r.a + r.b);
}
mint operator()(mint x) const { return a * x + b; }
Affine operator()(const Affine& r) const { return r * (*this); }
bool operator==(const Affine& r) const { return a == r.a && b == r.b; }
bool operator!=(const Affine& r) const { return a != r.a || b != r.b; }
friend ostream& operator<<(ostream& os, const Affine& r) {
os << "( " << r.a << ", " << r.b << " )";
return os;
}
};
/**
* @brief アフィン変換
*/#line 2 "math/affine-transformation.hpp"
template <typename mint>
struct Affine {
mint a, b;
constexpr Affine() : a(1), b(0) {}
constexpr Affine(mint _a, mint _b) : a(_a), b(_b) {}
// R(L(x))
friend Affine operator*(const Affine& l, const Affine& r) {
return Affine(l.a * r.a, l.b * r.a + r.b);
}
mint operator()(mint x) const { return a * x + b; }
Affine operator()(const Affine& r) const { return r * (*this); }
bool operator==(const Affine& r) const { return a == r.a && b == r.b; }
bool operator!=(const Affine& r) const { return a != r.a || b != r.b; }
friend ostream& operator<<(ostream& os, const Affine& r) {
os << "( " << r.a << ", " << r.b << " )";
return os;
}
};
/**
* @brief アフィン変換
*/