diff --git a/DP/tests/yosupo_cnt_distinct_subseq.test.cpp.md b/DP/tests/yosupo_cnt_distinct_subseq.test.cpp.md index 5af714a..a401bfe 100644 --- a/DP/tests/yosupo_cnt_distinct_subseq.test.cpp.md +++ b/DP/tests/yosupo_cnt_distinct_subseq.test.cpp.md @@ -126,22 +126,22 @@ data: \ % MD * b.inv().x % MD);\n }\n\n constexpr bool operator == (const ModInt&\ \ a) const { return x == a.x; }\n constexpr bool operator != (const ModInt&\ \ a) const { return x != a.x; }\n\n friend std::istream& operator >> (std::istream&\ - \ is, ModInt& x) {\n ll val; is >> val;\n x = ModInt(val);\n \ - \ return is;\n }\n constexpr friend std::ostream& operator << (std::ostream&\ - \ os, const ModInt& x) {\n return os << x.x;\n }\n\n constexpr ModInt\ - \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ - \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ - \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ - \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ - \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ - \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ - \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ - \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ - \ std::vector factorials, inv_factorials, invs;\n constexpr static\ - \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ - \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ - \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ - \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \ is, ModInt& other) {\n ll val; is >> val;\n other = ModInt(val);\n\ + \ return is;\n }\n constexpr friend std::ostream& operator << (std::ostream&\ + \ os, const ModInt& other) {\n return os << other.x;\n }\n\n constexpr\ + \ ModInt pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k)\ + \ {\n if (k & 1) ans *= tmp;\n tmp *= tmp;\n \ + \ k >>= 1;\n }\n return ans;\n }\n\n constexpr ModInt inv()\ + \ const {\n if (x < 1000111) {\n _precalc(1000111);\n \ + \ return invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n\ + \ while (b) {\n int q = a/b, t = a%b;\n a = b; b\ + \ = t;\n t = ax - bx*q;\n ax = bx; bx = t;\n }\n\ + \ assert(a == 1);\n if (ax < 0) ax += MD;\n return ax;\n\ + \ }\n\n static std::vector factorials, inv_factorials, invs;\n \ + \ constexpr static void _precalc(int n) {\n if (factorials.empty()) {\n\ + \ factorials = {1};\n inv_factorials = {1};\n \ + \ invs = {0};\n }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n\ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -182,7 +182,7 @@ data: isVerificationFile: true path: DP/tests/yosupo_cnt_distinct_subseq.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DP/tests/yosupo_cnt_distinct_subseq.test.cpp diff --git a/DataStructure/test/hld_vertexsetpathcomposite.test.cpp.md b/DataStructure/test/hld_vertexsetpathcomposite.test.cpp.md index e45771f..713b8fc 100644 --- a/DataStructure/test/hld_vertexsetpathcomposite.test.cpp.md +++ b/DataStructure/test/hld_vertexsetpathcomposite.test.cpp.md @@ -110,23 +110,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -301,7 +301,7 @@ data: isVerificationFile: true path: DataStructure/test/hld_vertexsetpathcomposite.test.cpp requiredBy: [] - timestamp: '2023-01-04 02:50:55+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DataStructure/test/hld_vertexsetpathcomposite.test.cpp diff --git a/DataStructure/test/link_cut_tree_vertexsetpathcomposite.test.cpp.md b/DataStructure/test/link_cut_tree_vertexsetpathcomposite.test.cpp.md index 460fcd1..5965b25 100644 --- a/DataStructure/test/link_cut_tree_vertexsetpathcomposite.test.cpp.md +++ b/DataStructure/test/link_cut_tree_vertexsetpathcomposite.test.cpp.md @@ -43,23 +43,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -212,7 +212,7 @@ data: isVerificationFile: true path: DataStructure/test/link_cut_tree_vertexsetpathcomposite.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DataStructure/test/link_cut_tree_vertexsetpathcomposite.test.cpp diff --git a/DataStructure/test/segment_tree_pointsetrangecomposite.test.cpp.md b/DataStructure/test/segment_tree_pointsetrangecomposite.test.cpp.md index 29e5bfe..758d46b 100644 --- a/DataStructure/test/segment_tree_pointsetrangecomposite.test.cpp.md +++ b/DataStructure/test/segment_tree_pointsetrangecomposite.test.cpp.md @@ -110,23 +110,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -201,7 +201,7 @@ data: isVerificationFile: true path: DataStructure/test/segment_tree_pointsetrangecomposite.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DataStructure/test/segment_tree_pointsetrangecomposite.test.cpp diff --git a/DataStructure/test/segment_tree_rangeaffinepointget.test.cpp.md b/DataStructure/test/segment_tree_rangeaffinepointget.test.cpp.md index c71f77f..f0c865e 100644 --- a/DataStructure/test/segment_tree_rangeaffinepointget.test.cpp.md +++ b/DataStructure/test/segment_tree_rangeaffinepointget.test.cpp.md @@ -173,23 +173,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -267,7 +267,7 @@ data: isVerificationFile: true path: DataStructure/test/segment_tree_rangeaffinepointget.test.cpp requiredBy: [] - timestamp: '2023-05-07 00:55:39+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DataStructure/test/segment_tree_rangeaffinepointget.test.cpp diff --git a/DataStructure/test/segment_tree_rangeaffinerangesum.test.cpp.md b/DataStructure/test/segment_tree_rangeaffinerangesum.test.cpp.md index 6aaa9de..973be55 100644 --- a/DataStructure/test/segment_tree_rangeaffinerangesum.test.cpp.md +++ b/DataStructure/test/segment_tree_rangeaffinerangesum.test.cpp.md @@ -145,23 +145,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -238,7 +238,7 @@ data: isVerificationFile: true path: DataStructure/test/segment_tree_rangeaffinerangesum.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DataStructure/test/segment_tree_rangeaffinerangesum.test.cpp diff --git a/DataStructure/test/splay_tree.test.cpp.md b/DataStructure/test/splay_tree.test.cpp.md index e89491d..926672b 100644 --- a/DataStructure/test/splay_tree.test.cpp.md +++ b/DataStructure/test/splay_tree.test.cpp.md @@ -43,23 +43,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -288,7 +288,7 @@ data: isVerificationFile: true path: DataStructure/test/splay_tree.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: DataStructure/test/splay_tree.test.cpp diff --git a/Math/modint.h.md b/Math/modint.h.md index 11c26e6..419c4cf 100644 --- a/Math/modint.h.md +++ b/Math/modint.h.md @@ -98,46 +98,46 @@ data: \ return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\n constexpr bool\ \ operator == (const ModInt& a) const { return x == a.x; }\n constexpr bool\ \ operator != (const ModInt& a) const { return x != a.x; }\n\n friend std::istream&\ - \ operator >> (std::istream& is, ModInt& x) {\n ll val; is >> val;\n \ - \ x = ModInt(val);\n return is;\n }\n constexpr friend std::ostream&\ - \ operator << (std::ostream& os, const ModInt& x) {\n return os << x.x;\n\ - \ }\n\n constexpr ModInt pow(ll k) const {\n ModInt ans = 1, tmp\ - \ = x;\n while (k) {\n if (k & 1) ans *= tmp;\n tmp\ - \ *= tmp;\n k >>= 1;\n }\n return ans;\n }\n\n \ - \ constexpr ModInt inv() const {\n if (x < 1000111) {\n _precalc(1000111);\n\ - \ return invs[x];\n }\n int a = x, b = MD, ax = 1, bx\ - \ = 0;\n while (b) {\n int q = a/b, t = a%b;\n a\ - \ = b; b = t;\n t = ax - bx*q;\n ax = bx; bx = t;\n \ - \ }\n assert(a == 1);\n if (ax < 0) ax += MD;\n return\ - \ ax;\n }\n\n static std::vector factorials, inv_factorials, invs;\n\ - \ constexpr static void _precalc(int n) {\n if (factorials.empty())\ - \ {\n factorials = {1};\n inv_factorials = {1};\n \ - \ invs = {0};\n }\n if (n > MD) n = MD;\n int old_sz\ - \ = factorials.size();\n if (n <= old_sz) return;\n\n factorials.resize(n);\n\ - \ inv_factorials.resize(n);\n invs.resize(n);\n\n for (int\ - \ i = old_sz; i < n; ++i) factorials[i] = factorials[i-1] * i;\n inv_factorials[n-1]\ - \ = factorials.back().pow(MD - 2);\n for (int i = n - 2; i >= old_sz; --i)\ - \ inv_factorials[i] = inv_factorials[i+1] * (i+1);\n for (int i = n-1;\ - \ i >= old_sz; --i) invs[i] = inv_factorials[i] * factorials[i-1];\n }\n\n\ - \ static int get_primitive_root() {\n static int primitive_root = 0;\n\ - \ if (!primitive_root) {\n primitive_root = [&]() {\n \ - \ std::set fac;\n int v = MD - 1;\n \ - \ for (ll i = 2; i * i <= v; i++)\n while (v % i == 0) fac.insert(i),\ - \ v /= i;\n if (v > 1) fac.insert(v);\n for (int\ - \ g = 1; g < MD; g++) {\n bool ok = true;\n \ - \ for (auto i : fac)\n if (ModInt(g).pow((MD - 1) /\ - \ i) == 1) {\n ok = false;\n \ - \ break;\n }\n if (ok) return g;\n\ - \ }\n return -1;\n }();\n }\n\ - \ return primitive_root;\n }\n\n static ModInt C(int n, int k) {\n\ - \ _precalc(n + 1);\n return factorials[n] * inv_factorials[k] *\ - \ inv_factorials[n-k];\n }\n \nprivate:\n // Internal, DO NOT USE.\n\ - \ // val must be in [0, 2*MD)\n constexpr inline __attribute__((always_inline))\ - \ ModInt& _set(ll v) {\n x = v >= MD ? v - MD : v;\n return *this;\n\ - \ }\n};\ntemplate std::vector> ModInt::factorials =\ - \ {1};\ntemplate std::vector> ModInt::inv_factorials =\ - \ {1};\ntemplate std::vector> ModInt::invs = {0};\n//\ - \ }}}\n" + \ operator >> (std::istream& is, ModInt& other) {\n ll val; is >> val;\n\ + \ other = ModInt(val);\n return is;\n }\n constexpr friend\ + \ std::ostream& operator << (std::ostream& os, const ModInt& other) {\n \ + \ return os << other.x;\n }\n\n constexpr ModInt pow(ll k) const {\n \ + \ ModInt ans = 1, tmp = x;\n while (k) {\n if (k & 1) ans\ + \ *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n return\ + \ ans;\n }\n\n constexpr ModInt inv() const {\n if (x < 1000111)\ + \ {\n _precalc(1000111);\n return invs[x];\n }\n\ + \ int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n \ + \ int q = a/b, t = a%b;\n a = b; b = t;\n t = ax - bx*q;\n\ + \ ax = bx; bx = t;\n }\n assert(a == 1);\n if\ + \ (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ + \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ + \ {\n if (factorials.empty()) {\n factorials = {1};\n \ + \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ + \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ + \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ + \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ + \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ + \ * (i+1);\n for (int i = n-1; i >= old_sz; --i) invs[i] = inv_factorials[i]\ + \ * factorials[i-1];\n }\n\n static int get_primitive_root() {\n \ + \ static int primitive_root = 0;\n if (!primitive_root) {\n \ + \ primitive_root = [&]() {\n std::set fac;\n \ + \ int v = MD - 1;\n for (ll i = 2; i * i <= v; i++)\n \ + \ while (v % i == 0) fac.insert(i), v /= i;\n if (v\ + \ > 1) fac.insert(v);\n for (int g = 1; g < MD; g++) {\n \ + \ bool ok = true;\n for (auto i : fac)\n \ + \ if (ModInt(g).pow((MD - 1) / i) == 1) {\n \ + \ ok = false;\n break;\n \ + \ }\n if (ok) return g;\n }\n \ + \ return -1;\n }();\n }\n return primitive_root;\n\ + \ }\n\n static ModInt C(int n, int k) {\n _precalc(n + 1);\n \ + \ return factorials[n] * inv_factorials[k] * inv_factorials[n-k];\n }\n\ + \ \nprivate:\n // Internal, DO NOT USE.\n // val must be in [0, 2*MD)\n\ + \ constexpr inline __attribute__((always_inline)) ModInt& _set(ll v) {\n \ + \ x = v >= MD ? v - MD : v;\n return *this;\n }\n};\ntemplate std::vector> ModInt::factorials = {1};\ntemplate \ + \ std::vector> ModInt::inv_factorials = {1};\ntemplate \ + \ std::vector> ModInt::invs = {0};\n// }}}\n" code: "// ModInt {{{\ntemplate struct ModInt {\n using ll = long long;\n\ \ int x;\n\n constexpr ModInt() : x(0) {}\n constexpr ModInt(ll v) {\ \ _set(v % MD + MD); }\n constexpr static int mod() { return MD; }\n constexpr\ @@ -161,23 +161,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -207,7 +207,7 @@ data: requiredBy: - String/hash.h - String/SuffixArray.h - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: LIBRARY_ALL_AC verifiedWith: - Math/tests/berlekamp_massey.test.cpp diff --git a/Math/tests/aizu_ntl_1_b_modulo_pow.test.cpp.md b/Math/tests/aizu_ntl_1_b_modulo_pow.test.cpp.md index 26d4114..295561a 100644 --- a/Math/tests/aizu_ntl_1_b_modulo_pow.test.cpp.md +++ b/Math/tests/aizu_ntl_1_b_modulo_pow.test.cpp.md @@ -68,23 +68,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -120,7 +120,7 @@ data: isVerificationFile: true path: Math/tests/aizu_ntl_1_b_modulo_pow.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/aizu_ntl_1_b_modulo_pow.test.cpp diff --git a/Math/tests/berlekamp_massey.test.cpp.md b/Math/tests/berlekamp_massey.test.cpp.md index 7fd9b9f..26d5e45 100644 --- a/Math/tests/berlekamp_massey.test.cpp.md +++ b/Math/tests/berlekamp_massey.test.cpp.md @@ -43,23 +43,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -149,7 +149,7 @@ data: isVerificationFile: true path: Math/tests/berlekamp_massey.test.cpp requiredBy: [] - timestamp: '2022-12-31 11:49:15+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/berlekamp_massey.test.cpp diff --git a/Math/tests/formal_power_series_multiply.test.cpp.md b/Math/tests/formal_power_series_multiply.test.cpp.md index b385ac0..3af919b 100644 --- a/Math/tests/formal_power_series_multiply.test.cpp.md +++ b/Math/tests/formal_power_series_multiply.test.cpp.md @@ -46,22 +46,22 @@ data: \ % MD * b.inv().x % MD);\n }\n\n constexpr bool operator == (const ModInt&\ \ a) const { return x == a.x; }\n constexpr bool operator != (const ModInt&\ \ a) const { return x != a.x; }\n\n friend std::istream& operator >> (std::istream&\ - \ is, ModInt& x) {\n ll val; is >> val;\n x = ModInt(val);\n \ - \ return is;\n }\n constexpr friend std::ostream& operator << (std::ostream&\ - \ os, const ModInt& x) {\n return os << x.x;\n }\n\n constexpr ModInt\ - \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ - \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ - \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ - \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ - \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ - \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ - \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ - \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ - \ std::vector factorials, inv_factorials, invs;\n constexpr static\ - \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ - \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ - \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ - \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \ is, ModInt& other) {\n ll val; is >> val;\n other = ModInt(val);\n\ + \ return is;\n }\n constexpr friend std::ostream& operator << (std::ostream&\ + \ os, const ModInt& other) {\n return os << other.x;\n }\n\n constexpr\ + \ ModInt pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k)\ + \ {\n if (k & 1) ans *= tmp;\n tmp *= tmp;\n \ + \ k >>= 1;\n }\n return ans;\n }\n\n constexpr ModInt inv()\ + \ const {\n if (x < 1000111) {\n _precalc(1000111);\n \ + \ return invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n\ + \ while (b) {\n int q = a/b, t = a%b;\n a = b; b\ + \ = t;\n t = ax - bx*q;\n ax = bx; bx = t;\n }\n\ + \ assert(a == 1);\n if (ax < 0) ax += MD;\n return ax;\n\ + \ }\n\n static std::vector factorials, inv_factorials, invs;\n \ + \ constexpr static void _precalc(int n) {\n if (factorials.empty()) {\n\ + \ factorials = {1};\n inv_factorials = {1};\n \ + \ invs = {0};\n }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n\ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -180,7 +180,7 @@ data: isVerificationFile: true path: Math/tests/formal_power_series_multiply.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/formal_power_series_multiply.test.cpp diff --git a/Math/tests/formal_power_series_multiply_any_mod.test.cpp.md b/Math/tests/formal_power_series_multiply_any_mod.test.cpp.md index 0ba2ec9..b1f6c7d 100644 --- a/Math/tests/formal_power_series_multiply_any_mod.test.cpp.md +++ b/Math/tests/formal_power_series_multiply_any_mod.test.cpp.md @@ -46,23 +46,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -181,7 +181,7 @@ data: isVerificationFile: true path: Math/tests/formal_power_series_multiply_any_mod.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/formal_power_series_multiply_any_mod.test.cpp diff --git a/Math/tests/matrix_mult.test.cpp.md b/Math/tests/matrix_mult.test.cpp.md index b91d7e4..71b7890 100644 --- a/Math/tests/matrix_mult.test.cpp.md +++ b/Math/tests/matrix_mult.test.cpp.md @@ -143,22 +143,22 @@ data: \ % MD * b.inv().x % MD);\n }\n\n constexpr bool operator == (const ModInt&\ \ a) const { return x == a.x; }\n constexpr bool operator != (const ModInt&\ \ a) const { return x != a.x; }\n\n friend std::istream& operator >> (std::istream&\ - \ is, ModInt& x) {\n ll val; is >> val;\n x = ModInt(val);\n \ - \ return is;\n }\n constexpr friend std::ostream& operator << (std::ostream&\ - \ os, const ModInt& x) {\n return os << x.x;\n }\n\n constexpr ModInt\ - \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ - \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ - \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ - \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ - \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ - \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ - \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ - \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ - \ std::vector factorials, inv_factorials, invs;\n constexpr static\ - \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ - \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ - \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ - \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \ is, ModInt& other) {\n ll val; is >> val;\n other = ModInt(val);\n\ + \ return is;\n }\n constexpr friend std::ostream& operator << (std::ostream&\ + \ os, const ModInt& other) {\n return os << other.x;\n }\n\n constexpr\ + \ ModInt pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k)\ + \ {\n if (k & 1) ans *= tmp;\n tmp *= tmp;\n \ + \ k >>= 1;\n }\n return ans;\n }\n\n constexpr ModInt inv()\ + \ const {\n if (x < 1000111) {\n _precalc(1000111);\n \ + \ return invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n\ + \ while (b) {\n int q = a/b, t = a%b;\n a = b; b\ + \ = t;\n t = ax - bx*q;\n ax = bx; bx = t;\n }\n\ + \ assert(a == 1);\n if (ax < 0) ax += MD;\n return ax;\n\ + \ }\n\n static std::vector factorials, inv_factorials, invs;\n \ + \ constexpr static void _precalc(int n) {\n if (factorials.empty()) {\n\ + \ factorials = {1};\n inv_factorials = {1};\n \ + \ invs = {0};\n }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n\ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -206,7 +206,7 @@ data: isVerificationFile: true path: Math/tests/matrix_mult.test.cpp requiredBy: [] - timestamp: '2022-12-29 18:10:21+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/matrix_mult.test.cpp diff --git a/Math/tests/ntt.test.cpp.md b/Math/tests/ntt.test.cpp.md index 4b1e0c3..e4a7a72 100644 --- a/Math/tests/ntt.test.cpp.md +++ b/Math/tests/ntt.test.cpp.md @@ -42,23 +42,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -157,7 +157,7 @@ data: isVerificationFile: true path: Math/tests/ntt.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/ntt.test.cpp diff --git a/Math/tests/ntt_any_mod.test.cpp.md b/Math/tests/ntt_any_mod.test.cpp.md index 239deb8..dc578d4 100644 --- a/Math/tests/ntt_any_mod.test.cpp.md +++ b/Math/tests/ntt_any_mod.test.cpp.md @@ -42,23 +42,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -157,7 +157,7 @@ data: isVerificationFile: true path: Math/tests/ntt_any_mod.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: Math/tests/ntt_any_mod.test.cpp diff --git a/String/SuffixArray.h.md b/String/SuffixArray.h.md index a74c470..3c8c1c0 100644 --- a/String/SuffixArray.h.md +++ b/String/SuffixArray.h.md @@ -163,23 +163,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -468,7 +468,7 @@ data: isVerificationFile: false path: String/SuffixArray.h requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: LIBRARY_ALL_AC verifiedWith: - String/tests/suffix_array.test.cpp diff --git a/String/hash.h.md b/String/hash.h.md index 6d28a69..db63879 100644 --- a/String/hash.h.md +++ b/String/hash.h.md @@ -60,92 +60,93 @@ data: \ return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\n constexpr bool\ \ operator == (const ModInt& a) const { return x == a.x; }\n constexpr bool\ \ operator != (const ModInt& a) const { return x != a.x; }\n\n friend std::istream&\ - \ operator >> (std::istream& is, ModInt& x) {\n ll val; is >> val;\n \ - \ x = ModInt(val);\n return is;\n }\n constexpr friend std::ostream&\ - \ operator << (std::ostream& os, const ModInt& x) {\n return os << x.x;\n\ - \ }\n\n constexpr ModInt pow(ll k) const {\n ModInt ans = 1, tmp\ - \ = x;\n while (k) {\n if (k & 1) ans *= tmp;\n tmp\ - \ *= tmp;\n k >>= 1;\n }\n return ans;\n }\n\n \ - \ constexpr ModInt inv() const {\n if (x < 1000111) {\n _precalc(1000111);\n\ - \ return invs[x];\n }\n int a = x, b = MD, ax = 1, bx\ - \ = 0;\n while (b) {\n int q = a/b, t = a%b;\n a\ - \ = b; b = t;\n t = ax - bx*q;\n ax = bx; bx = t;\n \ - \ }\n assert(a == 1);\n if (ax < 0) ax += MD;\n return\ - \ ax;\n }\n\n static std::vector factorials, inv_factorials, invs;\n\ - \ constexpr static void _precalc(int n) {\n if (factorials.empty())\ - \ {\n factorials = {1};\n inv_factorials = {1};\n \ - \ invs = {0};\n }\n if (n > MD) n = MD;\n int old_sz\ - \ = factorials.size();\n if (n <= old_sz) return;\n\n factorials.resize(n);\n\ - \ inv_factorials.resize(n);\n invs.resize(n);\n\n for (int\ - \ i = old_sz; i < n; ++i) factorials[i] = factorials[i-1] * i;\n inv_factorials[n-1]\ - \ = factorials.back().pow(MD - 2);\n for (int i = n - 2; i >= old_sz; --i)\ - \ inv_factorials[i] = inv_factorials[i+1] * (i+1);\n for (int i = n-1;\ - \ i >= old_sz; --i) invs[i] = inv_factorials[i] * factorials[i-1];\n }\n\n\ - \ static int get_primitive_root() {\n static int primitive_root = 0;\n\ - \ if (!primitive_root) {\n primitive_root = [&]() {\n \ - \ std::set fac;\n int v = MD - 1;\n \ - \ for (ll i = 2; i * i <= v; i++)\n while (v % i == 0) fac.insert(i),\ - \ v /= i;\n if (v > 1) fac.insert(v);\n for (int\ - \ g = 1; g < MD; g++) {\n bool ok = true;\n \ - \ for (auto i : fac)\n if (ModInt(g).pow((MD - 1) /\ - \ i) == 1) {\n ok = false;\n \ - \ break;\n }\n if (ok) return g;\n\ - \ }\n return -1;\n }();\n }\n\ - \ return primitive_root;\n }\n\n static ModInt C(int n, int k) {\n\ - \ _precalc(n + 1);\n return factorials[n] * inv_factorials[k] *\ - \ inv_factorials[n-k];\n }\n \nprivate:\n // Internal, DO NOT USE.\n\ - \ // val must be in [0, 2*MD)\n constexpr inline __attribute__((always_inline))\ - \ ModInt& _set(ll v) {\n x = v >= MD ? v - MD : v;\n return *this;\n\ - \ }\n};\ntemplate std::vector> ModInt::factorials =\ - \ {1};\ntemplate std::vector> ModInt::inv_factorials =\ - \ {1};\ntemplate std::vector> ModInt::invs = {0};\n//\ - \ }}}\n#line 2 \"String/hash.h\"\n\n// Hash {{{\n// Usage:\n// HashGenerator g(MAX_LENGTH)\n\ - //\n// auto h = g.hash(s)\n// g.equals(s, h, l1, r1, s, h, l2, r2)\n// g.cmp(s,\ - \ h, l1, r1, s, h, l2, r2)\n//\n// Tested:\n// - https://oj.vnoi.info/problem/substr\n\ - // - https://oj.vnoi.info/problem/paliny - max palin / binary search\n// - https://oj.vnoi.info/problem/dtksub\ - \ - hash for unordered_map\n// - https://oj.vnoi.info/problem/vostr -\ - \ cmp\n\nconst int MOD = 1e9 + 7;\nusing modular = ModInt;\n\nstruct Hash\ - \ {\n long long x;\n modular y;\n\n Hash operator + (const Hash& a) const\ - \ { return Hash{x + a.x, y + a.y}; }\n Hash operator - (const Hash& a) const\ - \ { return Hash{x - a.x, y - a.y}; }\n Hash operator * (const Hash& a) const\ - \ { return Hash{x * a.x, y * a.y}; }\n Hash operator * (int k) const { return\ - \ Hash{x*k, y*k}; }\n\n Hash& operator += (const Hash& a) { return *this =\ - \ *this + a; }\n Hash& operator -= (const Hash& a) { return *this = *this -\ - \ a; }\n Hash& operator *= (const Hash& a) { return *this = *this * a; }\n\ - };\nbool operator == (const Hash& a, const Hash& b) {\n return a.x == b.x &&\ - \ a.y == b.y;\n}\nbool operator < (const Hash& a, const Hash& b) {\n if (a.x\ - \ != b.x) return a.x < b.x;\n return a.y.x < b.y.x;\n}\nstd::ostream& operator\ - \ << (std::ostream& out, const Hash& h) {\n out << '(' << h.x << \", \" <<\ - \ h.y << ')';\n return out;\n}\n\n// hash function for std::unordered_map\n\ - namespace std {\n template<>\n struct hash {\n public:\n \ - \ size_t operator() (const Hash& h) const {\n return h.x\ - \ * 1000000009 + h.y.x;\n }\n };\n}\n\nstruct HashGenerator {\n\ - \ HashGenerator(int maxLen, int base = 311) {\n p.resize(maxLen + 1);\n\ - \ p[0] = {1, 1};\n for (int i = 1; i <= maxLen; i++) {\n \ - \ p[i] = p[i-1] * base;\n }\n }\n\n template\n\ - \ std::vector hash(const Container& s) const {\n std::vector\ - \ res(s.size());\n for (size_t i = 0; i < s.size(); i++) {\n \ - \ res[i] = p[i] * (int) s[i];\n }\n std::partial_sum(res.begin(),\ - \ res.end(), res.begin());\n return res;\n }\n\n Hash getHash(const\ - \ std::vector& h, int l, int r) const {\n return __getHash(h, l,\ - \ r) * p[p.size() - 1 - l];\n }\n\n // compare [l1, r1] vs [l2, r2]\n \ - \ bool equals(\n const std::vector& h1, int l1, int r1,\n \ - \ const std::vector& h2, int l2, int r2) const {\n assert(0\ - \ <= l1 && l1 <= r1 && r1 < (int) h1.size());\n assert(0 <= l2 && l2 <=\ - \ r2 && r2 < (int) h2.size());\n if (r1 - l1 != r2 - l2) return false;\n\ - \n return getHash(h1, l1, r1) == getHash(h2, l2, r2);\n }\n\n //\ - \ Returns length of max common prefix of h1[l1, r1] and h2[l2, r2]\n // length\ - \ = 0 -> first character of 2 substrings are different.\n int maxCommonPrefix(\n\ - \ const std::vector& h1, int l1, int r1,\n const std::vector&\ + \ operator >> (std::istream& is, ModInt& other) {\n ll val; is >> val;\n\ + \ other = ModInt(val);\n return is;\n }\n constexpr friend\ + \ std::ostream& operator << (std::ostream& os, const ModInt& other) {\n \ + \ return os << other.x;\n }\n\n constexpr ModInt pow(ll k) const {\n \ + \ ModInt ans = 1, tmp = x;\n while (k) {\n if (k & 1) ans\ + \ *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n return\ + \ ans;\n }\n\n constexpr ModInt inv() const {\n if (x < 1000111)\ + \ {\n _precalc(1000111);\n return invs[x];\n }\n\ + \ int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n \ + \ int q = a/b, t = a%b;\n a = b; b = t;\n t = ax - bx*q;\n\ + \ ax = bx; bx = t;\n }\n assert(a == 1);\n if\ + \ (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ + \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ + \ {\n if (factorials.empty()) {\n factorials = {1};\n \ + \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ + \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ + \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ + \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ + \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ + \ * (i+1);\n for (int i = n-1; i >= old_sz; --i) invs[i] = inv_factorials[i]\ + \ * factorials[i-1];\n }\n\n static int get_primitive_root() {\n \ + \ static int primitive_root = 0;\n if (!primitive_root) {\n \ + \ primitive_root = [&]() {\n std::set fac;\n \ + \ int v = MD - 1;\n for (ll i = 2; i * i <= v; i++)\n \ + \ while (v % i == 0) fac.insert(i), v /= i;\n if (v\ + \ > 1) fac.insert(v);\n for (int g = 1; g < MD; g++) {\n \ + \ bool ok = true;\n for (auto i : fac)\n \ + \ if (ModInt(g).pow((MD - 1) / i) == 1) {\n \ + \ ok = false;\n break;\n \ + \ }\n if (ok) return g;\n }\n \ + \ return -1;\n }();\n }\n return primitive_root;\n\ + \ }\n\n static ModInt C(int n, int k) {\n _precalc(n + 1);\n \ + \ return factorials[n] * inv_factorials[k] * inv_factorials[n-k];\n }\n\ + \ \nprivate:\n // Internal, DO NOT USE.\n // val must be in [0, 2*MD)\n\ + \ constexpr inline __attribute__((always_inline)) ModInt& _set(ll v) {\n \ + \ x = v >= MD ? v - MD : v;\n return *this;\n }\n};\ntemplate std::vector> ModInt::factorials = {1};\ntemplate \ + \ std::vector> ModInt::inv_factorials = {1};\ntemplate \ + \ std::vector> ModInt::invs = {0};\n// }}}\n#line 2 \"String/hash.h\"\ + \n\n// Hash {{{\n// Usage:\n// HashGenerator g(MAX_LENGTH)\n//\n// auto h = g.hash(s)\n\ + // g.equals(s, h, l1, r1, s, h, l2, r2)\n// g.cmp(s, h, l1, r1, s, h, l2, r2)\n\ + //\n// Tested:\n// - https://oj.vnoi.info/problem/substr\n// - https://oj.vnoi.info/problem/paliny\ + \ - max palin / binary search\n// - https://oj.vnoi.info/problem/dtksub - hash\ + \ for unordered_map\n// - https://oj.vnoi.info/problem/vostr - cmp\n\nconst\ + \ int MOD = 1e9 + 7;\nusing modular = ModInt;\n\nstruct Hash {\n long\ + \ long x;\n modular y;\n\n Hash operator + (const Hash& a) const { return\ + \ Hash{x + a.x, y + a.y}; }\n Hash operator - (const Hash& a) const { return\ + \ Hash{x - a.x, y - a.y}; }\n Hash operator * (const Hash& a) const { return\ + \ Hash{x * a.x, y * a.y}; }\n Hash operator * (int k) const { return Hash{x*k,\ + \ y*k}; }\n\n Hash& operator += (const Hash& a) { return *this = *this + a;\ + \ }\n Hash& operator -= (const Hash& a) { return *this = *this - a; }\n \ + \ Hash& operator *= (const Hash& a) { return *this = *this * a; }\n};\nbool operator\ + \ == (const Hash& a, const Hash& b) {\n return a.x == b.x && a.y == b.y;\n\ + }\nbool operator < (const Hash& a, const Hash& b) {\n if (a.x != b.x) return\ + \ a.x < b.x;\n return a.y.x < b.y.x;\n}\nstd::ostream& operator << (std::ostream&\ + \ out, const Hash& h) {\n out << '(' << h.x << \", \" << h.y << ')';\n return\ + \ out;\n}\n\n// hash function for std::unordered_map\nnamespace std {\n template<>\n\ + \ struct hash {\n public:\n size_t operator() (const\ + \ Hash& h) const {\n return h.x * 1000000009 + h.y.x;\n \ + \ }\n };\n}\n\nstruct HashGenerator {\n HashGenerator(int maxLen, int\ + \ base = 311) {\n p.resize(maxLen + 1);\n p[0] = {1, 1};\n \ + \ for (int i = 1; i <= maxLen; i++) {\n p[i] = p[i-1] * base;\n \ + \ }\n }\n\n template\n std::vector hash(const\ + \ Container& s) const {\n std::vector res(s.size());\n for\ + \ (size_t i = 0; i < s.size(); i++) {\n res[i] = p[i] * (int) s[i];\n\ + \ }\n std::partial_sum(res.begin(), res.end(), res.begin());\n \ + \ return res;\n }\n\n Hash getHash(const std::vector& h, int\ + \ l, int r) const {\n return __getHash(h, l, r) * p[p.size() - 1 - l];\n\ + \ }\n\n // compare [l1, r1] vs [l2, r2]\n bool equals(\n const\ + \ std::vector& h1, int l1, int r1,\n const std::vector&\ \ h2, int l2, int r2) const {\n assert(0 <= l1 && l1 <= r1 && r1 < (int)\ - \ h1.size());\n assert(0 <= l2 && l2 <= r2 && r2 < (int) h2.size());\n\n\ - \ int len1 = r1 - l1 + 1;\n int len2 = r2 - l2 + 1;\n\n int\ - \ res = -1, left = 0, right = std::min(len1, len2) - 1;\n while (left <=\ - \ right) {\n int mid = (left + right) / 2;\n if (equals(h1,\ - \ l1, l1 + mid, h2, l2, l2 + mid)) {\n res = mid;\n \ - \ left = mid + 1;\n } else {\n right = mid - 1;\n\ - \ }\n }\n return res + 1;\n /* C++20\n \ - \ auto r = std::views::iota(0, std::min(len1, len2));\n auto res = std::ranges::partition_point(\n\ + \ h1.size());\n assert(0 <= l2 && l2 <= r2 && r2 < (int) h2.size());\n\ + \ if (r1 - l1 != r2 - l2) return false;\n\n return getHash(h1, l1,\ + \ r1) == getHash(h2, l2, r2);\n }\n\n // Returns length of max common prefix\ + \ of h1[l1, r1] and h2[l2, r2]\n // length = 0 -> first character of 2 substrings\ + \ are different.\n int maxCommonPrefix(\n const std::vector&\ + \ h1, int l1, int r1,\n const std::vector& h2, int l2, int r2)\ + \ const {\n assert(0 <= l1 && l1 <= r1 && r1 < (int) h1.size());\n \ + \ assert(0 <= l2 && l2 <= r2 && r2 < (int) h2.size());\n\n int len1\ + \ = r1 - l1 + 1;\n int len2 = r2 - l2 + 1;\n\n int res = -1, left\ + \ = 0, right = std::min(len1, len2) - 1;\n while (left <= right) {\n \ + \ int mid = (left + right) / 2;\n if (equals(h1, l1, l1 +\ + \ mid, h2, l2, l2 + mid)) {\n res = mid;\n left\ + \ = mid + 1;\n } else {\n right = mid - 1;\n \ + \ }\n }\n return res + 1;\n /* C++20\n auto r\ + \ = std::views::iota(0, std::min(len1, len2));\n auto res = std::ranges::partition_point(\n\ \ r,\n [&] (int mid) {\n return\ \ equals(h1, l1, l1+mid, h2, l2, l2+mid);\n });\n return\ \ *res;\n */\n }\n\n // compare s1[l1, r1] and s2[l2, r2]\n template> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -193,7 +193,7 @@ data: isVerificationFile: true path: String/tests/aizu_alds_14_b_string_hash.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: String/tests/aizu_alds_14_b_string_hash.test.cpp diff --git a/String/tests/lcp.test.cpp.md b/String/tests/lcp.test.cpp.md index 3ca6e0e..a774cfb 100644 --- a/String/tests/lcp.test.cpp.md +++ b/String/tests/lcp.test.cpp.md @@ -144,23 +144,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -321,7 +321,7 @@ data: isVerificationFile: true path: String/tests/lcp.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: String/tests/lcp.test.cpp diff --git a/String/tests/suffix_array.test.cpp.md b/String/tests/suffix_array.test.cpp.md index d1488d6..32cff46 100644 --- a/String/tests/suffix_array.test.cpp.md +++ b/String/tests/suffix_array.test.cpp.md @@ -145,23 +145,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -320,7 +320,7 @@ data: isVerificationFile: true path: String/tests/suffix_array.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: String/tests/suffix_array.test.cpp diff --git a/String/tests/suffix_array_queries.test.cpp.md b/String/tests/suffix_array_queries.test.cpp.md index d1bee2f..370cab5 100644 --- a/String/tests/suffix_array_queries.test.cpp.md +++ b/String/tests/suffix_array_queries.test.cpp.md @@ -145,23 +145,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -322,7 +322,7 @@ data: isVerificationFile: true path: String/tests/suffix_array_queries.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: String/tests/suffix_array_queries.test.cpp diff --git a/String/tests/yukicoder_1408_string_hash_lcp.test.cpp.md b/String/tests/yukicoder_1408_string_hash_lcp.test.cpp.md index bd56995..d50a525 100644 --- a/String/tests/yukicoder_1408_string_hash_lcp.test.cpp.md +++ b/String/tests/yukicoder_1408_string_hash_lcp.test.cpp.md @@ -70,23 +70,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -198,7 +198,7 @@ data: isVerificationFile: true path: String/tests/yukicoder_1408_string_hash_lcp.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: String/tests/yukicoder_1408_string_hash_lcp.test.cpp diff --git a/String/tests/zfunc_hash.test.cpp.md b/String/tests/zfunc_hash.test.cpp.md index 2822653..c1aa804 100644 --- a/String/tests/zfunc_hash.test.cpp.md +++ b/String/tests/zfunc_hash.test.cpp.md @@ -70,23 +70,23 @@ data: \ ModInt& b) {\n return ModInt()._set(a % MD * b.inv().x % MD);\n }\n\ \n constexpr bool operator == (const ModInt& a) const { return x == a.x; }\n\ \ constexpr bool operator != (const ModInt& a) const { return x != a.x; }\n\ - \n friend std::istream& operator >> (std::istream& is, ModInt& x) {\n \ - \ ll val; is >> val;\n x = ModInt(val);\n return is;\n }\n\ - \ constexpr friend std::ostream& operator << (std::ostream& os, const ModInt&\ - \ x) {\n return os << x.x;\n }\n\n constexpr ModInt pow(ll k) const\ - \ {\n ModInt ans = 1, tmp = x;\n while (k) {\n if (k\ - \ & 1) ans *= tmp;\n tmp *= tmp;\n k >>= 1;\n }\n\ - \ return ans;\n }\n\n constexpr ModInt inv() const {\n if\ - \ (x < 1000111) {\n _precalc(1000111);\n return invs[x];\n\ - \ }\n int a = x, b = MD, ax = 1, bx = 0;\n while (b) {\n\ - \ int q = a/b, t = a%b;\n a = b; b = t;\n t =\ - \ ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a == 1);\n\ - \ if (ax < 0) ax += MD;\n return ax;\n }\n\n static std::vector\ - \ factorials, inv_factorials, invs;\n constexpr static void _precalc(int n)\ - \ {\n if (factorials.empty()) {\n factorials = {1};\n \ - \ inv_factorials = {1};\n invs = {0};\n }\n if (n\ - \ > MD) n = MD;\n int old_sz = factorials.size();\n if (n <= old_sz)\ - \ return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ + \n friend std::istream& operator >> (std::istream& is, ModInt& other) {\n \ + \ ll val; is >> val;\n other = ModInt(val);\n return is;\n\ + \ }\n constexpr friend std::ostream& operator << (std::ostream& os, const\ + \ ModInt& other) {\n return os << other.x;\n }\n\n constexpr ModInt\ + \ pow(ll k) const {\n ModInt ans = 1, tmp = x;\n while (k) {\n \ + \ if (k & 1) ans *= tmp;\n tmp *= tmp;\n k >>=\ + \ 1;\n }\n return ans;\n }\n\n constexpr ModInt inv() const\ + \ {\n if (x < 1000111) {\n _precalc(1000111);\n return\ + \ invs[x];\n }\n int a = x, b = MD, ax = 1, bx = 0;\n while\ + \ (b) {\n int q = a/b, t = a%b;\n a = b; b = t;\n \ + \ t = ax - bx*q;\n ax = bx; bx = t;\n }\n assert(a\ + \ == 1);\n if (ax < 0) ax += MD;\n return ax;\n }\n\n static\ + \ std::vector factorials, inv_factorials, invs;\n constexpr static\ + \ void _precalc(int n) {\n if (factorials.empty()) {\n factorials\ + \ = {1};\n inv_factorials = {1};\n invs = {0};\n \ + \ }\n if (n > MD) n = MD;\n int old_sz = factorials.size();\n \ + \ if (n <= old_sz) return;\n\n factorials.resize(n);\n inv_factorials.resize(n);\n\ \ invs.resize(n);\n\n for (int i = old_sz; i < n; ++i) factorials[i]\ \ = factorials[i-1] * i;\n inv_factorials[n-1] = factorials.back().pow(MD\ \ - 2);\n for (int i = n - 2; i >= old_sz; --i) inv_factorials[i] = inv_factorials[i+1]\ @@ -188,7 +188,7 @@ data: isVerificationFile: true path: String/tests/zfunc_hash.test.cpp requiredBy: [] - timestamp: '2022-12-29 17:34:35+08:00' + timestamp: '2023-10-15 09:43:20+08:00' verificationStatus: TEST_ACCEPTED verifiedWith: [] documentation_of: String/tests/zfunc_hash.test.cpp