@@ -18,40 +18,40 @@ data:
1818 links :
1919 - https://judge.yosupo.jp/problem/point_add_range_sum
2020 bundledCode : " #line 1 \" test/point_add_range_sum.test.cpp\"\n #define PROBLEM \" \
21- https://judge.yosupo.jp/problem/point_add_range_sum\"\n\n #line 1 \" weilycoder/ds/point_add_range_sum .hpp\" \
22- \n\n\n\n /**\n * @file point_add_range_sum .hpp\n * @brief Point Add Range Sum using \
23- \ Fenwick Tree \n */ \n\n #line 1 \" weilycoder/ds/group.hpp \"\n\n\n\n /**\n * @file \
24- \ group.hpp \n * @brief Group Definitions \n */\n\n #include <limits> \n\n namespace \
25- \ weilycoder { \n /** \n * @brief Additive Group \n * @tparam T Type of the elements \n \
26- \ */ \n template <typename T> struct AddGroup { \n using value_type = T; \n static\
27- \ constexpr T operation (const T &a, const T &b ) { return a + b ; }\n static constexpr \
28- \ T identity() { return T{}; } \n static constexpr T inverse(const T &a) { return \
29- \ -a; } \n }; \n\n /** \n * @brief Additive Monoid \n * @tparam T Type of the elements \n \
30- \ */ \n template <typename T> struct AddMonoid { \n using value_type = T; \n static \
31- \ constexpr T operation(const T &a, const T &b) { return a + b; } \n static constexpr \
32- \ T identity() { return T{}; } \n }; \n\n /** \n * @brief Minimum Monoid for numbers \n \
33- \ * @tparam T Type of the elements, must support std::numeric_limits \n */ \n template \
34- \ <typename T> struct NumberMinMonoid { \n using value_type = T; \n static constexpr\
35- \ T operation(const T &a, const T &b) { return a < b ? a : b; } \n static constexpr \
36- \ T identity() { return std::numeric_limits<T>::max(); } \n }; \n\n /** \n * @brief \
37- \ Maximum Monoid for numbers \n * @tparam T Type of the elements, must support \
38- \ std::numeric_limits \n */ \n template <typename T> struct NumberMaxMonoid { \n \
39- \ using value_type = T; \n static constexpr T operation(const T &a, const T &b) \
40- \ { return a > b ? a : b; } \n static constexpr T identity() { return std::numeric_limits<T>::min(); \
41- \ } \n }; \n } // namespace weilycoder \n \n\n #line 10 \" weilycoder/ds/point_add_range_sum.hpp \" \
42- \n #include <cstddef> \n #include < stdexcept>\n #include <vector>\n\n namespace weilycoder\
43- \ { \n /** \n * @brief Point Add Range Sum using Fenwick Tree (Binary Indexed Tree)\n \
44- \ * @tparam Group A group defining the operation and identity element,\n * \
45- \ must be associative and commutative (i.e. Abelian group).\n */\n \
46- template <typename Group> struct PointAddRangeSum {\n using value_type = typename\
47- \ Group::value_type; \n using T = value_type;\n\n private:\n std::vector<T> data;\n \
48- \n public: \n /** \n * @brief Constructs a PointAddRangeSum for n elements initialized\
49- \ to the \n * identity element\n * @param n Number of elements\n */\n \
50- \ explicit PointAddRangeSum(size_t n) : data(n + 1, Group::identity()) {}\n\n \
51- \ /** \n * @brief Constructs a PointAddRangeSum from an initial array\n *\
52- \ @param initial Initial array of elements\n */\n explicit PointAddRangeSum(const\
53- \ std::vector<T> &initial)\n : data(initial.size() + 1, Group::identity())\
54- \ { \n for (size_t i = 1; i <= initial.size(); ++i) {\n data[i] = Group::operation(data[i],\
21+ https://judge.yosupo.jp/problem/point_add_range_sum\"\n\n #line 1 \" weilycoder/ds/group .hpp\" \
22+ \n\n\n\n /**\n * @file group .hpp\n * @brief Group Definitions \n */ \n\n #include \
23+ \ <limits> \n\n namespace weilycoder { \n /**\n * @brief Additive Group \n * @tparam \
24+ \ T Type of the elements \n */\n template <typename T> struct AddGroup { \n using \
25+ \ value_type = T; \n static constexpr T operation(const T &a, const T &b) { return \
26+ \ a + b; } \n static constexpr T identity() { return T{}; } \n static constexpr \
27+ \ T inverse (const T &a) { return -a ; }\n }; \n\n /** \n * @brief Additive Monoid \n \
28+ \ * @tparam T Type of the elements \n */ \n template <typename T> struct AddMonoid \
29+ \ { \n using value_type = T; \n static constexpr T operation(const T &a, const \
30+ \ T &b) { return a + b; } \n static constexpr T identity() { return T{}; } \n }; \n \
31+ \n /** \n * @brief Minimum Monoid for numbers \n * @tparam T Type of the elements, \
32+ \ must support std::numeric_limits \n */ \n template <typename T> struct NumberMinMonoid \
33+ \ { \n using value_type = T; \n static constexpr T operation(const T &a, const \
34+ \ T &b) { return a < b ? a : b; } \n static constexpr T identity() { return std::numeric_limits<T>::max(); \
35+ \ } \n }; \n\n /** \n * @brief Maximum Monoid for numbers \n * @tparam T Type of the \
36+ \ elements, must support std::numeric_limits\n */ \n template <typename T> struct \
37+ \ NumberMaxMonoid { \n using value_type = T; \n static constexpr T operation(const \
38+ \ T &a, const T &b) { return a > b ? a : b; } \n static constexpr T identity() \
39+ \ { return std::numeric_limits<T>::min(); } \n }; \n } // namespace weilycoder \n\n \
40+ \n #line 1 \" weilycoder/ds/point_add_range_sum.hpp \"\n\n\n\n /** \n * @file point_add_range_sum.hpp \n \
41+ \ * @brief Point Add Range Sum using Fenwick Tree \n */ \n\n #include <cstddef> \n \
42+ #include <stdexcept>\n #include <vector>\n\n namespace weilycoder { \n /** \n * @brief \
43+ \ Point Add Range Sum using Fenwick Tree (Binary Indexed Tree)\n * @tparam Group \
44+ \ A group defining the operation and identity element,\n * must \
45+ \ be associative and commutative (i.e. Abelian group).\n */\n template <typename \
46+ \ Group> struct PointAddRangeSum {\n using value_type = typename Group::value_type; \n \
47+ \ using T = value_type;\n\n private:\n std::vector<T> data;\n\n public: \n /** \n \
48+ \ * @brief Constructs a PointAddRangeSum for n elements initialized to the \n \
49+ \ * identity element\n * @param n Number of elements\n */\n explicit \
50+ \ PointAddRangeSum(size_t n) : data(n + 1, Group::identity()) {}\n\n /** \n \
51+ \ * @brief Constructs a PointAddRangeSum from an initial array\n * @param initial \
52+ \ Initial array of elements\n */\n explicit PointAddRangeSum(const std::vector<T> \
53+ \ &initial)\n : data(initial.size() + 1, Group::identity()) { \n for (size_t \
54+ \ i = 1; i <= initial.size(); ++i) {\n data[i] = Group::operation(data[i],\
5555 \ initial[i - 1]);\n size_t j = i + (i & -i);\n if (j < data.size())\n \
5656 \ data[j] = Group::operation(data[j], data[i]);\n }\n }\n\n /**\n \
5757 \ * @brief Constructs a PointAddRangeSum from an initial range\n * @tparam\
7676 \ T range_sum(size_t l, size_t r) const {\n if (l > r || r > size())\n \
7777 \ throw std::out_of_range(\" Invalid range for range_sum\" );\n return Group::operation(prefix_sum(r),\
7878 \ Group::inverse(prefix_sum(l)));\n }\n };\n } // namespace weilycoder\n\n\n #line\
79- \ 4 \" test/point_add_range_sum.test.cpp\"\n #include <cstdint>\n #include <iostream>\n \
80- #line 7 \" test/point_add_range_sum.test.cpp\"\n using namespace std;\n using namespace\
79+ \ 5 \" test/point_add_range_sum.test.cpp\"\n #include <cstdint>\n #include <iostream>\n \
80+ #line 8 \" test/point_add_range_sum.test.cpp\"\n using namespace std;\n using namespace\
8181 \ weilycoder;\n\n int main() {\n cin.tie(nullptr)->sync_with_stdio(false);\n \
8282 \ cin.exceptions(cin.failbit | cin.badbit);\n size_t n, q;\n cin >> n >> q;\n \
8383 \n vector<uint64_t> initial(n, 0);\n for (size_t i = 0; i < n; ++i)\n cin\
@@ -87,23 +87,23 @@ data:
8787 \ size_t l, r;\n cin >> l >> r;\n cout << pasr.range_sum(l, r) <<\
8888 \ '\\ n';\n }\n }\n return 0;\n }\n "
8989 code : " #define PROBLEM \" https://judge.yosupo.jp/problem/point_add_range_sum\"\n \
90- \n #include \" ../weilycoder/ds/point_add_range_sum .hpp\"\n #include <cstdint> \n \
91- #include <iostream >\n #include <vector> \n using namespace std; \n using namespace\
92- \ weilycoder;\n\n int main() {\n cin.tie(nullptr)->sync_with_stdio(false);\n \
93- \ cin.exceptions(cin.failbit | cin.badbit);\n size_t n, q;\n cin >> n >> q;\n \
90+ \n #include \" ../weilycoder/ds/group .hpp\"\n #include \" ../weilycoder/ds/point_add_range_sum.hpp \" \
91+ \n #include <cstdint >\n #include <iostream> \n #include <vector> \n using namespace\
92+ \ std; \n using namespace weilycoder;\n\n int main() {\n cin.tie(nullptr)->sync_with_stdio(false);\n \
93+ \ cin.exceptions(cin.failbit | cin.badbit);\n size_t n, q;\n cin >> n >> q;\n \
9494 \n vector<uint64_t> initial(n, 0);\n for (size_t i = 0; i < n; ++i)\n cin\
9595 \ >> initial[i];\n\n PointAddRangeSum<AddGroup<uint64_t>> pasr(initial);\n while\
9696 \ (q--) {\n int type;\n cin >> type;\n if (type == 0) {\n size_t\
9797 \ i, x;\n cin >> i >> x;\n pasr.point_add(i, x);\n } else {\n \
9898 \ size_t l, r;\n cin >> l >> r;\n cout << pasr.range_sum(l, r) <<\
9999 \ '\\ n';\n }\n }\n return 0;\n }"
100100 dependsOn :
101- - weilycoder/ds/point_add_range_sum.hpp
102101 - weilycoder/ds/group.hpp
102+ - weilycoder/ds/point_add_range_sum.hpp
103103 isVerificationFile : true
104104 path : test/point_add_range_sum.test.cpp
105105 requiredBy : []
106- timestamp : ' 2025-10-31 09:52:58 +08:00'
106+ timestamp : ' 2025-11-01 07:16:21 +08:00'
107107 verificationStatus : TEST_ACCEPTED
108108 verifiedWith : []
109109documentation_of : test/point_add_range_sum.test.cpp
0 commit comments