Skip to content

Commit 90b313e

Browse files
authored
[auto-verifier] docs commit f66a551
1 parent 44cdb50 commit 90b313e

26 files changed

+320
-46
lines changed

index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ data:
3939
- icon: ':heavy_check_mark:'
4040
path: weilycoder/number-theory/prime.hpp
4141
title: Prime Number Utilities
42+
- name: weilycoder/poly
43+
pages:
44+
- icon: ':heavy_check_mark:'
45+
path: weilycoder/poly/karatsuba.hpp
46+
title: Multiply two polynomials using the Karatsuba algorithm.
4247
verificationCategories:
4348
- name: test
4449
pages:
@@ -48,6 +53,9 @@ data:
4853
- icon: ':heavy_check_mark:'
4954
path: test/biconnected_components.test.cpp
5055
title: test/biconnected_components.test.cpp
56+
- icon: ':heavy_check_mark:'
57+
path: test/convolution_mod_2_64.test.cpp
58+
title: test/convolution_mod_2_64.test.cpp
5159
- icon: ':heavy_check_mark:'
5260
path: test/many_aplusb.test.cpp
5361
title: test/many_aplusb.test.cpp

test/aplusb.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ data:
160160
isVerificationFile: true
161161
path: test/aplusb.test.cpp
162162
requiredBy: []
163-
timestamp: '2025-11-01 13:01:38+08:00'
163+
timestamp: '2025-11-05 00:26:33+08:00'
164164
verificationStatus: TEST_ACCEPTED
165165
verifiedWith: []
166166
documentation_of: test/aplusb.test.cpp

test/biconnected_components.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ data:
112112
isVerificationFile: true
113113
path: test/biconnected_components.test.cpp
114114
requiredBy: []
115-
timestamp: '2025-11-01 13:01:38+08:00'
115+
timestamp: '2025-11-05 00:26:33+08:00'
116116
verificationStatus: TEST_ACCEPTED
117117
verifiedWith: []
118118
documentation_of: test/biconnected_components.test.cpp
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
data:
3+
_extendedDependsOn:
4+
- icon: ':heavy_check_mark:'
5+
path: weilycoder/poly/karatsuba.hpp
6+
title: Multiply two polynomials using the Karatsuba algorithm.
7+
_extendedRequiredBy: []
8+
_extendedVerifiedWith: []
9+
_isVerificationFailed: false
10+
_pathExtension: cpp
11+
_verificationStatusIcon: ':heavy_check_mark:'
12+
attributes:
13+
'*NOT_SPECIAL_COMMENTS*': ''
14+
PROBLEM: https://judge.yosupo.jp/problem/convolution_mod_2_64
15+
links:
16+
- https://judge.yosupo.jp/problem/convolution_mod_2_64
17+
bundledCode: "#line 1 \"test/convolution_mod_2_64.test.cpp\"\n#define PROBLEM \"\
18+
https://judge.yosupo.jp/problem/convolution_mod_2_64\"\n\n#line 1 \"weilycoder/poly/karatsuba.hpp\"\
19+
\n\n\n\n#include <algorithm>\n#include <iterator>\n#include <type_traits>\n#include\
20+
\ <vector>\n\nnamespace weilycoder {\n/**\n * @brief Multiply two polynomials\
21+
\ using the Karatsuba algorithm.\n * @tparam InputIt Iterator type for input polynomials.\n\
22+
\ * @tparam OutputIt Iterator type for output polynomial.\n * @tparam Threshold\
23+
\ Size threshold to switch to standard multiplication.\n * @param a_begin Iterator\
24+
\ to the beginning of the first polynomial.\n * @param a_end Iterator to the end\
25+
\ of the first polynomial.\n * @param b_begin Iterator to the beginning of the\
26+
\ second polynomial.\n * @param b_end Iterator to the end of the second polynomial.\n\
27+
\ * @param result_begin Iterator to the beginning of the result polynomial.\n\
28+
\ */\ntemplate <typename InputIt, typename OutputIt, size_t Threshold = 32>\n\
29+
void karatsuba_multiply(InputIt a_begin, InputIt a_end, InputIt b_begin, InputIt\
30+
\ b_end,\n OutputIt result_begin) {\n using T = typename\
31+
\ std::iterator_traits<InputIt>::value_type;\n\n static_assert(\n std::is_base_of<std::random_access_iterator_tag,\n\
32+
\ typename std::iterator_traits<InputIt>::iterator_category>::value,\n\
33+
\ \"karatsuba_multiply requires InputIt to be a random access iterator\"\
34+
);\n static_assert(std::is_base_of<\n std::random_access_iterator_tag,\n\
35+
\ typename std::iterator_traits<OutputIt>::iterator_category>::value,\n\
36+
\ \"karatsuba_multiply requires OutputIt to be a random access\
37+
\ iterator\");\n\n size_t a_size = std::distance(a_begin, a_end);\n size_t b_size\
38+
\ = std::distance(b_begin, b_end);\n\n if (a_size <= Threshold || b_size <= Threshold)\
39+
\ {\n // Base case: use standard multiplication\n for (size_t i = 0; i <\
40+
\ a_size; ++i)\n for (size_t j = 0; j < b_size; ++j)\n result_begin[i\
41+
\ + j] += a_begin[i] * b_begin[j];\n return;\n }\n\n size_t res_size = a_size\
42+
\ + b_size - 1;\n size_t half_size = std::max(a_size, b_size) / 2;\n\n // Split\
43+
\ the polynomials\n auto a_mid = (a_size > half_size) ? a_begin + half_size :\
44+
\ a_end;\n auto b_mid = (b_size > half_size) ? b_begin + half_size : b_end;\n\
45+
\n size_t a_low_size = std::distance(a_begin, a_mid);\n size_t b_low_size =\
46+
\ std::distance(b_begin, b_mid);\n size_t a_high_size = std::distance(a_mid,\
47+
\ a_end);\n size_t b_high_size = std::distance(b_mid, b_end);\n size_t a_max_size\
48+
\ = std::max(a_low_size, a_high_size);\n size_t b_max_size = std::max(b_low_size,\
49+
\ b_high_size);\n size_t part_size = a_max_size + b_max_size - 1;\n\n std::vector<T>\
50+
\ z0(part_size);\n std::vector<T> z1(part_size);\n std::vector<T> z2(part_size);\n\
51+
\n // z0 = a_low * b_low\n karatsuba_multiply(a_begin, a_mid, b_begin, b_mid,\
52+
\ z0.begin());\n // z2 = a_high * b_high\n karatsuba_multiply(a_mid, a_end,\
53+
\ b_mid, b_end, z2.begin());\n\n // z1 = (a_low + a_high) * (b_low + b_high)\
54+
\ - z0 - z2\n std::vector<T> a_sum(std::max(a_low_size, a_high_size));\n for\
55+
\ (size_t i = 0; i < a_low_size; ++i)\n a_sum[i] += a_begin[i];\n for (size_t\
56+
\ i = 0; i < a_high_size; ++i)\n a_sum[i] += a_mid[i];\n std::vector<T> b_sum(std::max(b_low_size,\
57+
\ b_high_size));\n for (size_t i = 0; i < b_low_size; ++i)\n b_sum[i] += b_begin[i];\n\
58+
\ for (size_t i = 0; i < b_high_size; ++i)\n b_sum[i] += b_mid[i];\n karatsuba_multiply(a_sum.begin(),\
59+
\ a_sum.end(), b_sum.begin(), b_sum.end(),\n z1.begin());\n\
60+
\ for (size_t i = 0; i < part_size; ++i)\n z1[i] -= z0[i] + z2[i];\n\n //\
61+
\ Combine results\n for (size_t i = 0; i < part_size; ++i) {\n if (i >= res_size)\n\
62+
\ break;\n result_begin[i] += z0[i];\n }\n for (size_t i = 0; i < part_size;\
63+
\ ++i) {\n if (i + half_size >= res_size)\n break;\n result_begin[i\
64+
\ + half_size] += z1[i];\n }\n for (size_t i = 0; i < part_size; ++i) {\n \
65+
\ if (i + 2 * half_size >= res_size)\n break;\n result_begin[i + 2 *\
66+
\ half_size] += z2[i];\n }\n}\n\n/**\n * @brief Multiply two polynomials using\
67+
\ the Karatsuba algorithm.\n * @tparam T Coefficient type of the polynomials.\n\
68+
\ * @tparam Threshold Size threshold to switch to standard multiplication.\n *\
69+
\ @param a First polynomial coefficients.\n * @param b Second polynomial coefficients.\n\
70+
\ * @return Resulting polynomial coefficients after multiplication.\n */\ntemplate\
71+
\ <typename T, size_t Threshold = 32>\nstd::vector<T> karatsuba_multiply(const\
72+
\ std::vector<T> &a, const std::vector<T> &b) {\n using I_It = typename std::vector<T>::const_iterator;\n\
73+
\ using O_It = typename std::vector<T>::iterator;\n std::vector<T> result(a.size()\
74+
\ + b.size() - 1);\n karatsuba_multiply<I_It, O_It, Threshold>(a.begin(), a.end(),\
75+
\ b.begin(), b.end(),\n result.begin());\n\
76+
\ return result;\n}\n} // namespace weilycoder\n\n\n#line 4 \"test/convolution_mod_2_64.test.cpp\"\
77+
\n#include <cstdint>\n#include <iostream>\n#line 7 \"test/convolution_mod_2_64.test.cpp\"\
78+
\nusing namespace std;\nusing namespace weilycoder;\n\nint main() {\n cin.tie(nullptr)->sync_with_stdio(false);\n\
79+
\ cin.exceptions(cin.badbit | cin.failbit);\n size_t n, m;\n cin >> n >> m;\n\
80+
\n vector<uint64_t> a(n), b(m);\n for (size_t i = 0; i < n; ++i)\n cin >>\
81+
\ a[i];\n for (size_t j = 0; j < m; ++j)\n cin >> b[j];\n\n auto c = karatsuba_multiply(a,\
82+
\ b);\n for (size_t k = 0; k < n + m - 1; ++k)\n cout << c[k] << (k + 1 ==\
83+
\ n + m - 1 ? '\\n' : ' ');\n return 0;\n}\n"
84+
code: "#define PROBLEM \"https://judge.yosupo.jp/problem/convolution_mod_2_64\"\n\
85+
\n#include \"../weilycoder/poly/karatsuba.hpp\"\n#include <cstdint>\n#include\
86+
\ <iostream>\n#include <vector>\nusing namespace std;\nusing namespace weilycoder;\n\
87+
\nint main() {\n cin.tie(nullptr)->sync_with_stdio(false);\n cin.exceptions(cin.badbit\
88+
\ | cin.failbit);\n size_t n, m;\n cin >> n >> m;\n\n vector<uint64_t> a(n),\
89+
\ b(m);\n for (size_t i = 0; i < n; ++i)\n cin >> a[i];\n for (size_t j =\
90+
\ 0; j < m; ++j)\n cin >> b[j];\n\n auto c = karatsuba_multiply(a, b);\n \
91+
\ for (size_t k = 0; k < n + m - 1; ++k)\n cout << c[k] << (k + 1 == n + m\
92+
\ - 1 ? '\\n' : ' ');\n return 0;\n}"
93+
dependsOn:
94+
- weilycoder/poly/karatsuba.hpp
95+
isVerificationFile: true
96+
path: test/convolution_mod_2_64.test.cpp
97+
requiredBy: []
98+
timestamp: '2025-11-05 00:26:33+08:00'
99+
verificationStatus: TEST_ACCEPTED
100+
verifiedWith: []
101+
documentation_of: test/convolution_mod_2_64.test.cpp
102+
layout: document
103+
redirect_from:
104+
- /verify/test/convolution_mod_2_64.test.cpp
105+
- /verify/test/convolution_mod_2_64.test.cpp.html
106+
title: test/convolution_mod_2_64.test.cpp
107+
---

test/many_aplusb.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ data:
162162
isVerificationFile: true
163163
path: test/many_aplusb.test.cpp
164164
requiredBy: []
165-
timestamp: '2025-11-01 13:01:38+08:00'
165+
timestamp: '2025-11-05 00:26:33+08:00'
166166
verificationStatus: TEST_ACCEPTED
167167
verifiedWith: []
168168
documentation_of: test/many_aplusb.test.cpp

test/many_aplusb_128bit.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ data:
161161
isVerificationFile: true
162162
path: test/many_aplusb_128bit.test.cpp
163163
requiredBy: []
164-
timestamp: '2025-11-01 13:01:38+08:00'
164+
timestamp: '2025-11-05 00:26:33+08:00'
165165
verificationStatus: TEST_ACCEPTED
166166
verifiedWith: []
167167
documentation_of: test/many_aplusb_128bit.test.cpp

test/point_add_range_sum.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ data:
103103
isVerificationFile: true
104104
path: test/point_add_range_sum.test.cpp
105105
requiredBy: []
106-
timestamp: '2025-11-01 13:01:38+08:00'
106+
timestamp: '2025-11-05 00:26:33+08:00'
107107
verificationStatus: TEST_ACCEPTED
108108
verifiedWith: []
109109
documentation_of: test/point_add_range_sum.test.cpp

test/point_set_range_composite.test.cpp.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ data:
1818
\ \"https://judge.yosupo.jp/problem/point_set_range_composite\"\n\n#line 1 \"\
1919
weilycoder/ds/segment_tree.hpp\"\n\n\n\n/**\n * @file segment_tree.hpp\n * @brief\
2020
\ Segment Tree Data Structure\n */\n\n#include <cstddef>\n#include <limits>\n\
21-
#include <stdexcept>\n#include <vector>\n\nnamespace weilycoder {\ntemplate <typename\
21+
#include <stdexcept>\n#include <vector>\n\nnamespace weilycoder {\n/**\n * @brief\
22+
\ Segment Tree Base Class that uses heap indexing for child nodes\n * @tparam\
23+
\ _Monoid The monoid defining the operation and identity\n * @tparam _ptr_t The\
24+
\ pointer type used for indexing nodes (default: size_t)\n */\ntemplate <typename\
2225
\ _Monoid, typename _ptr_t = size_t> struct SegmentTreeHeapSon {\nprotected:\n\
2326
\ using T = typename _Monoid::value_type;\n using ptr_t = _ptr_t;\n using Monoid\
2427
\ = _Monoid;\n static constexpr ptr_t null = std::numeric_limits<ptr_t>::max();\n\
@@ -163,7 +166,7 @@ data:
163166
isVerificationFile: true
164167
path: test/point_set_range_composite.test.cpp
165168
requiredBy: []
166-
timestamp: '2025-11-01 13:01:38+08:00'
169+
timestamp: '2025-11-05 00:26:33+08:00'
167170
verificationStatus: TEST_ACCEPTED
168171
verifiedWith: []
169172
documentation_of: test/point_set_range_composite.test.cpp

test/point_set_range_composite2.test.cpp.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ data:
1818
\ \"https://judge.yosupo.jp/problem/point_set_range_composite\"\n\n#line 1 \"\
1919
weilycoder/ds/segment_tree.hpp\"\n\n\n\n/**\n * @file segment_tree.hpp\n * @brief\
2020
\ Segment Tree Data Structure\n */\n\n#include <cstddef>\n#include <limits>\n\
21-
#include <stdexcept>\n#include <vector>\n\nnamespace weilycoder {\ntemplate <typename\
21+
#include <stdexcept>\n#include <vector>\n\nnamespace weilycoder {\n/**\n * @brief\
22+
\ Segment Tree Base Class that uses heap indexing for child nodes\n * @tparam\
23+
\ _Monoid The monoid defining the operation and identity\n * @tparam _ptr_t The\
24+
\ pointer type used for indexing nodes (default: size_t)\n */\ntemplate <typename\
2225
\ _Monoid, typename _ptr_t = size_t> struct SegmentTreeHeapSon {\nprotected:\n\
2326
\ using T = typename _Monoid::value_type;\n using ptr_t = _ptr_t;\n using Monoid\
2427
\ = _Monoid;\n static constexpr ptr_t null = std::numeric_limits<ptr_t>::max();\n\
@@ -163,7 +166,7 @@ data:
163166
isVerificationFile: true
164167
path: test/point_set_range_composite2.test.cpp
165168
requiredBy: []
166-
timestamp: '2025-11-01 13:01:38+08:00'
169+
timestamp: '2025-11-05 00:26:33+08:00'
167170
verificationStatus: TEST_ACCEPTED
168171
verifiedWith: []
169172
documentation_of: test/point_set_range_composite2.test.cpp

test/primality_test.test.cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ data:
9999
isVerificationFile: true
100100
path: test/primality_test.test.cpp
101101
requiredBy: []
102-
timestamp: '2025-11-01 13:01:38+08:00'
102+
timestamp: '2025-11-05 00:26:33+08:00'
103103
verificationStatus: TEST_ACCEPTED
104104
verifiedWith: []
105105
documentation_of: test/primality_test.test.cpp

0 commit comments

Comments
 (0)