62# ifndef TPL_SEGMENT_TREE_H
63# define TPL_SEGMENT_TREE_H
68# include <initializer_list>
70# include <type_traits>
98 template <
typename F,
typename T>
141 template <
typename T,
class Op>
150 void build(
size_t node,
const size_t start,
const size_t end)
155 const size_t mid = start + (end - start) / 2;
156 build(2 * node, start, mid);
157 build(2 * node + 1, mid + 1, end);
161 void update_impl(
size_t node,
const size_t start,
const size_t end,
162 const size_t idx,
const T & delta)
170 if (
const size_t mid = start + (end - start) / 2; idx <= mid)
173 update_impl(2 * node + 1, mid + 1, end, idx, delta);
178 void set_impl(
size_t node,
const size_t start,
const size_t end,
179 const size_t idx,
const T & val)
187 if (
const size_t mid = start + (end - start) / 2; idx <= mid)
188 set_impl(2 * node, start, mid, idx, val);
190 set_impl(2 * node + 1, mid + 1, end, idx, val);
196 const size_t l,
const size_t r)
const
198 if (
r < start || end <
l)
201 if (
l <= start
and end <=
r)
204 const size_t mid = start + (end - start) / 2;
209 template <
class Getter>
219 template <
class Getter>
225 tree(node) = getter(start);
229 const size_t mid = start + (end - start) / 2;
234 template <
class AlephIt>
239 for (; it.has_curr(); it.next_ne())
240 tmp(i++) = it.get_curr();
242 auto getter = [&tmp](
size_t j) {
return tmp(j); };
258 const T &
id, Op oper = Op())
259 :
tree(num == 0 ? 1 : 4 * num, id),
279 const T &
id, Op oper = Op())
285 auto it = il.begin();
297 const T &
id, Op oper = Op())
312 const T &
id, Op oper = Op())
327 const T &
id, Op oper = Op())
345 std::is_nothrow_move_constructible_v<Array<T>>
and
346 std::is_nothrow_move_constructible_v<T>
and
347 std::is_nothrow_move_constructible_v<Op>)
374 <<
"Gen_Segment_Tree::update: index " << i <<
" >= size " <<
n;
385 void set(
const size_t i,
const T & val)
388 <<
"Gen_Segment_Tree::set: index " << i <<
" >= size " <<
n;
405 <<
"Gen_Segment_Tree::query: r=" <<
r <<
" >= n=" <<
n;
407 <<
"Gen_Segment_Tree::query: l=" <<
l <<
" > r=" <<
r;
422 <<
"Gen_Segment_Tree::get: index " << i <<
" >= size " <<
n;
428 [[nodiscard]]
constexpr size_t size() const noexcept {
return n; }
431 [[nodiscard]]
constexpr bool is_empty() const noexcept {
return n == 0; }
440 for (
size_t i = 0; i <
n; ++i)
455 std::is_nothrow_swappable_v<T>
and std::is_nothrow_swappable_v<Op>)
462 constexpr bool may_throw =
463 not std::is_nothrow_swappable_v<T> or not std::is_nothrow_swappable_v<Op>;
464 if constexpr (may_throw)
466 tree.swap(other.tree);
467 std::swap(
n, other.n);
468 if constexpr (not may_throw)
511 template <
typename T>
524 :
Base(num, init_val,
T())
584 template <std::totally_ordered T>
597 const T & init_val = std::numeric_limits<T>::max())
598 :
Base(num, init_val,
std::numeric_limits<
T>::
max())
659 template <std::totally_ordered T>
672 const T & init_val = std::numeric_limits<T>::lowest())
673 :
Base(num, init_val,
std::numeric_limits<
T>::lowest())
682 :
Base(il,
std::numeric_limits<
T>::lowest())
743 template <
typename P>
745 std::equality_comparable<typename P::lazy_type>
and
747 const typename P::value_type& v1,
748 const typename P::value_type& v2,
749 const typename P::lazy_type& lz1,
750 const typename P::lazy_type& lz2,
753 typename P::value_type;
754 typename P::lazy_type;
755 { p.combine(v1, v2) } -> std::convertible_to<typename P::value_type>;
756 { p.apply(v1, lz1,
count) } -> std::convertible_to<typename P::value_type>;
757 { p.compose(lz1, lz2) } -> std::convertible_to<typename P::lazy_type>;
758 { p.value_identity() } -> std::convertible_to<typename P::value_type>;
759 { p.lazy_identity() } -> std::convertible_to<typename P::lazy_type>;
775 template <
typename T>
781 static constexpr T combine(
const T & a,
const T & b)
noexcept
786 static constexpr T apply(
const T & val,
const T & delta,
787 size_t count)
noexcept
789 return val + delta *
static_cast<T>(
count);
793 const T & new_lazy)
noexcept
795 return old_lazy + new_lazy;
815 template <std::totally_ordered T>
821 static constexpr T combine(
const T & a,
const T & b)
noexcept
823 return a <= b ? a : b;
826 static constexpr T apply(
const T & val,
const T & delta,
833 const T & new_lazy)
noexcept
835 return old_lazy + new_lazy;
840 return std::numeric_limits<T>::max();
859 template <std::totally_ordered T>
865 static constexpr T combine(
const T & a,
const T & b)
noexcept
867 return a >= b ? a : b;
870 static constexpr T apply(
const T & val,
const T & delta,
877 const T & new_lazy)
noexcept
879 return old_lazy + new_lazy;
884 return std::numeric_limits<T>::lowest();
909 template <
typename T>
915 static constexpr T combine(
const T & a,
const T & b)
noexcept
921 size_t count)
noexcept
923 return lz.first ? lz.second *
static_cast<T>(
count) : val;
929 return new_lz.first ? new_lz : old_lz;
969 template <
typename Policy>
970 requires SegmentTreePolicy<Policy>
984 void push_down(
size_t node,
const size_t start,
const size_t end)
const
986 if (
lazy(node) ==
pol.lazy_identity())
989 const size_t mid = start + (end - start) / 2;
990 const size_t left = 2 * node;
991 const size_t right = 2 * node + 1;
999 lazy(node) =
pol.lazy_identity();
1002 void build(
size_t node,
const size_t start,
const size_t end)
1007 const size_t mid = start + (end - start) / 2;
1008 build(2 * node, start, mid);
1009 build(2 * node + 1, mid + 1, end);
1014 const size_t l,
const size_t r,
const lazy_type & val)
1016 if (
r < start or end <
l)
1019 if (
l <= start
and end <=
r)
1021 tree(node) =
pol.apply(
tree(node), val, end - start + 1);
1028 const size_t mid = start + (end - start) / 2;
1035 const size_t l,
const size_t r)
const
1037 if (
r < start or end <
l)
1038 return pol.value_identity();
1040 if (
l <= start
and end <=
r)
1045 const size_t mid = start + (end - start) / 2;
1051 void set_impl(
size_t node,
const size_t start,
const size_t end,
1057 lazy(node) =
pol.lazy_identity();
1063 if (
const size_t mid = start + (end - start) / 2; idx <= mid)
1064 set_impl(2 * node, start, mid, idx, val);
1066 set_impl(2 * node + 1, mid + 1, end, idx, val);
1071 template <
class Getter>
1078 template <
class Getter>
1084 tree(node) = getter(start);
1088 const size_t mid = start + (end - start) / 2;
1093 template <
class AlephIt>
1098 for (; it.has_curr(); it.next_ne())
1099 tmp(i++) = it.get_curr();
1101 auto getter = [&tmp](
size_t j) {
return tmp(j); };
1107 return n == 0 ? 1 : 4 *
n;
1114 Policy p = Policy())
1115 :
tree(num == 0 ? 1 : 4 * num, p.value_identity()),
1116 lazy(num == 0 ? 1 : 4 * num, p.lazy_identity()),
1125 Policy p = Policy())
1126 :
tree(il.
size() == 0 ? 1 : 4 * il.
size(), p.value_identity()),
1127 lazy(il.
size() == 0 ? 1 : 4 * il.
size(), p.lazy_identity()),
1132 auto it = il.
begin();
1139 Policy p = Policy())
1150 Policy p = Policy())
1161 Policy p = Policy())
1180 std::is_nothrow_move_constructible_v<Array<value_type>>
and
1181 std::is_nothrow_move_constructible_v<Array<lazy_type>>
and
1182 std::is_nothrow_move_constructible_v<Policy>)
1195 noexcept(
noexcept(
swap(other)))
1212 <<
"Gen_Lazy_Segment_Tree::update: r=" <<
r <<
" >= n=" <<
n;
1214 <<
"Gen_Lazy_Segment_Tree::update: l=" <<
l <<
" > r=" <<
r;
1239 <<
"Gen_Lazy_Segment_Tree::set: index " << i <<
" >= size " <<
n;
1258 <<
"Gen_Lazy_Segment_Tree::query: r=" <<
r <<
" >= n=" <<
n;
1260 <<
"Gen_Lazy_Segment_Tree::query: l=" <<
l <<
" > r=" <<
r;
1275 [[nodiscard]]
constexpr size_t size() const noexcept {
return n; }
1278 [[nodiscard]]
constexpr bool is_empty() const noexcept {
return n == 0; }
1287 for (
size_t i = 0; i <
n; ++i)
1308 std::swap(
n, other.n);
1317 template <
typename T>
1333 template <std::totally_ordered T>
1349 template <std::totally_ordered T>
1389 template <
typename T>
1390 requires std::is_arithmetic_v<T>
and std::is_signed_v<T>
1403 static constexpr T INF = std::numeric_limits<T>::max();
1404 static constexpr T NEG_INF = std::numeric_limits<T>::lowest();
1414 const auto &
l =
tree(2 * node);
1415 const auto &
r =
tree(2 * node + 1);
1417 tree(node).sum =
l.sum +
r.sum;
1420 if (
l.max_val >
r.max_val)
1422 tree(node).max_val =
l.max_val;
1423 tree(node).count_max =
l.count_max;
1424 tree(node).second_max = std::max(
l.second_max,
r.max_val);
1426 else if (
l.max_val <
r.max_val)
1428 tree(node).max_val =
r.max_val;
1429 tree(node).count_max =
r.count_max;
1430 tree(node).second_max = std::max(
l.max_val,
r.second_max);
1434 tree(node).max_val =
l.max_val;
1435 tree(node).count_max =
l.count_max +
r.count_max;
1436 tree(node).second_max = std::max(
l.second_max,
r.second_max);
1440 if (
l.min_val <
r.min_val)
1442 tree(node).min_val =
l.min_val;
1443 tree(node).count_min =
l.count_min;
1444 tree(node).second_min = std::min(
l.second_min,
r.min_val);
1446 else if (
l.min_val >
r.min_val)
1448 tree(node).min_val =
r.min_val;
1449 tree(node).count_min =
r.count_min;
1450 tree(node).second_min = std::min(
l.min_val,
r.second_min);
1454 tree(node).min_val =
l.min_val;
1455 tree(node).count_min =
l.count_min +
r.count_min;
1456 tree(node).second_min = std::min(
l.second_min,
r.second_min);
1465 auto & nd =
tree(child);
1466 if (v >= nd.max_val)
1469 nd.sum -=
static_cast<T>(nd.count_max) * (nd.max_val - v);
1473 if (nd.min_val == nd.max_val)
1475 if (nd.second_min == nd.max_val)
1481 nd.lazy_chmin = std::min(nd.lazy_chmin, v);
1482 nd.lazy_chmax = std::min(nd.lazy_chmax, v);
1487 auto & nd =
tree(child);
1488 if (v <= nd.min_val)
1491 nd.sum +=
static_cast<T>(nd.count_min) * (v - nd.min_val);
1494 if (nd.max_val == nd.min_val)
1496 if (nd.second_max == nd.min_val)
1502 nd.lazy_chmax = std::max(nd.lazy_chmax, v);
1503 nd.lazy_chmin = std::max(nd.lazy_chmin, v);
1508 auto & nd =
tree(node);
1519 if (nd.lazy_chmin !=
INF)
1523 nd.lazy_chmin =
INF;
1527 void build(
size_t node,
size_t start,
size_t end)
1532 const size_t mid = start + (end - start) / 2;
1533 build(2 * node, start, mid);
1534 build(2 * node + 1, mid + 1, end);
1538 void chmin_impl(
size_t node,
const size_t start,
const size_t end,
1539 const size_t l,
const size_t r,
T v)
1541 if (
r < start or end <
l or
tree(node).max_val <= v)
1544 if (
l <= start
and end <=
r and tree(node).second_max < v)
1551 const size_t mid = start + (end - start) / 2;
1557 void chmax_impl(
size_t node,
const size_t start,
const size_t end,
1558 const size_t l,
const size_t r,
T v)
1560 if (
r < start or end <
l or
tree(node).min_val >= v)
1563 if (
l <= start
and end <=
r and tree(node).second_min > v)
1570 const size_t mid = start + (end - start) / 2;
1577 const size_t l,
const size_t r)
const
1579 if (
r < start or end <
l)
1582 if (
l <= start
and end <=
r)
1583 return tree(node).sum;
1586 const size_t mid = start + (end - start) / 2;
1592 const size_t l,
const size_t r)
const
1594 if (
r < start or end <
l)
1597 if (
l <= start
and end <=
r)
1598 return tree(node).max_val;
1601 const size_t mid = start + (end - start) / 2;
1607 const size_t l,
const size_t r)
const
1609 if (
r < start or end <
l)
1612 if (
l <= start
and end <=
r)
1613 return tree(node).min_val;
1616 const size_t mid = start + (end - start) / 2;
1621 template <
class Getter>
1628 template <
class Getter>
1638 const size_t mid = start + (end - start) / 2;
1647 for (
size_t i = 0; i <
tree.size(); ++i)
1680 auto it = il.begin();
1727 for (
auto it =
values.get_it(); it.has_curr(); it.next_ne())
1728 tmp(i++) = it.get_curr();
1743 std::is_nothrow_move_constructible_v<Array<Node>>)
1755 std::is_nothrow_move_assignable_v<Array<Node>>)
1765 void chmin(
const size_t l,
const size_t r,
const T & v)
1768 <<
"Segment_Tree_Beats::chmin: r=" <<
r <<
" >= n=" <<
n;
1770 <<
"Segment_Tree_Beats::chmin: l=" <<
l <<
" > r=" <<
r;
1779 void chmax(
const size_t l,
const size_t r,
const T & v)
1782 <<
"Segment_Tree_Beats::chmax: r=" <<
r <<
" >= n=" <<
n;
1784 <<
"Segment_Tree_Beats::chmax: l=" <<
l <<
" > r=" <<
r;
1796 <<
"Segment_Tree_Beats::query_sum: r=" <<
r <<
" >= n=" <<
n;
1798 <<
"Segment_Tree_Beats::query_sum: l=" <<
l <<
" > r=" <<
r;
1810 <<
"Segment_Tree_Beats::query_max: r=" <<
r <<
" >= n=" <<
n;
1812 <<
"Segment_Tree_Beats::query_max: l=" <<
l <<
" > r=" <<
r;
1824 <<
"Segment_Tree_Beats::query_min: r=" <<
r <<
" >= n=" <<
n;
1826 <<
"Segment_Tree_Beats::query_min: l=" <<
l <<
" > r=" <<
r;
1838 [[nodiscard]]
constexpr size_t size() const noexcept {
return n; }
1841 [[nodiscard]]
constexpr bool is_empty() const noexcept {
return n == 0; }
1847 for (
size_t i = 0; i <
n; ++i)
1855 tree.swap(other.tree);
1856 std::swap(
n, other.n);
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Standard functor implementations and comparison objects.
Simple dynamic array with automatic resizing and functional operations.
void swap(Array &s) noexcept
Swap this with s
static Array create(const size_t n)
Create an array with n logical elements.
Doubly-linked list (defined in tpl_dynList.H).
Lazy segment tree with range update and range query.
void build(size_t node, const size_t start, const size_t end)
void point_update(const size_t i, const lazy_type &delta)
Point update: apply delta to a[i].
Gen_Lazy_Segment_Tree(const Array< value_type > &values, Policy p=Policy())
Construct from an Array<value_type>.
void set_impl(size_t node, const size_t start, const size_t end, const size_t idx, const value_type &val)
Gen_Lazy_Segment_Tree(const std::vector< value_type > &values, Policy p=Policy())
Construct from a std::vector.
Gen_Lazy_Segment_Tree & operator=(const Gen_Lazy_Segment_Tree &)=default
constexpr size_t size() const noexcept
Number of logical elements.
void update_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r, const lazy_type &val)
void fill_and_build(Getter getter)
typename Policy::value_type value_type
Gen_Lazy_Segment_Tree & operator=(Gen_Lazy_Segment_Tree &&other) noexcept(noexcept(swap(other)))
Exchange this tree with another, which is left with the previous elements of this one.
value_type query(const size_t l, const size_t r) const
Range query over [l, r].
constexpr bool is_empty() const noexcept
True if the tree contains no elements.
Array< value_type > values() const
Reconstruct all original values into an Array.
Gen_Lazy_Segment_Tree(const DynList< value_type > &values, Policy p=Policy())
Construct from a DynList.
void update(const size_t l, const size_t r, const lazy_type &val)
Range update: apply val to every a[i] with l <= i <= r.
void set(const size_t i, const value_type &val)
Set a[i] = val.
value_type query_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r) const
typename Policy::lazy_type lazy_type
Gen_Lazy_Segment_Tree(std::initializer_list< value_type > il, Policy p=Policy())
Construct from an initializer list.
void fill_from_aleph_it(AlephIt it)
size_t alloc_size() const
Gen_Lazy_Segment_Tree(Gen_Lazy_Segment_Tree &&other) noexcept(std::is_nothrow_move_constructible_v< Array< value_type > > and std::is_nothrow_move_constructible_v< Array< lazy_type > > and std::is_nothrow_move_constructible_v< Policy >)
Take the elements of another tree, which is left empty.
Gen_Lazy_Segment_Tree(const size_t num, const value_type &init_val=value_type(), Policy p=Policy())
Construct with num elements, all equal to init_val.
Gen_Lazy_Segment_Tree(const Gen_Lazy_Segment_Tree &)=default
void fill_leaves_recursive(size_t node, size_t start, size_t end, Getter &getter)
void push_down(size_t node, const size_t start, const size_t end) const
value_type get(const size_t i) const
Retrieve the value a[i].
void swap(Gen_Lazy_Segment_Tree &other) noexcept(std::is_nothrow_swappable_v< Policy >)
Swap this tree with other in O(1).
Segment tree over an arbitrary associative binary operation.
void set(const size_t i, const T &val)
Set a[i] = val.
void update_impl(size_t node, const size_t start, const size_t end, const size_t idx, const T &delta)
T query(const size_t l, const size_t r) const
Range query over [l, r].
Gen_Segment_Tree(const size_t num, const T &init_val, const T &id, Op oper=Op())
Construct a segment tree with num elements, all equal to init_val.
Gen_Segment_Tree(const Array< T > &values, const T &id, Op oper=Op())
Construct from an Array<T>.
Gen_Segment_Tree & operator=(const Gen_Segment_Tree &)=default
void set_impl(size_t node, const size_t start, const size_t end, const size_t idx, const T &val)
Gen_Segment_Tree(const DynList< T > &values, const T &id, Op oper=Op())
Construct from a DynList<T>.
void swap_identity_and_op(Gen_Segment_Tree &other)
void fill_from_aleph_it(AlephIt it)
void fill_leaves_recursive(size_t node, size_t start, size_t end, Getter &getter)
T query_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r) const
Gen_Segment_Tree(std::initializer_list< T > il, const T &id, Op oper=Op())
Construct from an initializer list.
Gen_Segment_Tree(const Gen_Segment_Tree &)=default
void fill_and_build(Getter getter)
constexpr bool is_empty() const noexcept
True if the tree contains no elements.
Gen_Segment_Tree & operator=(Gen_Segment_Tree &&other) noexcept(noexcept(swap(other)))
Exchange this tree with another, which is left with the previous elements of this one.
Array< T > values() const
Reconstruct all original values into an Array.
T get(const size_t i) const
Retrieve the value a[i].
void update(const size_t i, const T &delta)
Point update: a[i] = Op(a[i], delta).
void swap(Gen_Segment_Tree &other) noexcept(std::is_nothrow_swappable_v< T > and std::is_nothrow_swappable_v< Op >)
Swap this tree with other in O(1).
constexpr size_t size() const noexcept
Number of logical elements.
void build(size_t node, const size_t start, const size_t end)
Gen_Segment_Tree(const std::vector< T > &values, const T &id, Op oper=Op())
Construct from a std::vector<T>.
Gen_Segment_Tree(Gen_Segment_Tree &&other) noexcept(std::is_nothrow_move_constructible_v< Array< T > > and std::is_nothrow_move_constructible_v< T > and std::is_nothrow_move_constructible_v< Op >)
Take the elements of another tree, which is left empty.
Ji Driver's Segment Tree (Segment Tree Beats).
void chmax_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r, T v)
void chmax(const size_t l, const size_t r, const T &v)
Range chmax: for each i in [l, r], set a[i] = max(a[i], v).
constexpr size_t size() const noexcept
Number of logical elements.
T query_min_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r) const
T query_sum(const size_t l, const size_t r) const
Range sum query over [l, r].
static constexpr T NEG_INF
T get(const size_t i) const
Retrieve the value at position i.
void build(size_t node, size_t start, size_t end)
T query_max_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r) const
T query_max(const size_t l, const size_t r) const
Range max query over [l, r].
void push_chmin_to_child(size_t child, T v) const
Segment_Tree_Beats(const Array< T > &values)
Construct from an Array<T>.
void fill_and_build(Getter getter)
Segment_Tree_Beats(const size_t num, const T &init_val=T())
Construct with num elements, all equal to init_val.
Segment_Tree_Beats(const Segment_Tree_Beats &)=default
Segment_Tree_Beats(const std::vector< T > &values)
Construct from a std::vector<T>.
Segment_Tree_Beats & operator=(const Segment_Tree_Beats &)=default
void push_chmax_to_child(size_t child, T v) const
void chmin(const size_t l, const size_t r, const T &v)
Range chmin: for each i in [l, r], set a[i] = min(a[i], v).
void push_down(size_t node) const
void chmin_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r, T v)
Array< T > values() const
Reconstruct all values into an Array.
T query_min(const size_t l, const size_t r) const
Range min query over [l, r].
void swap(Segment_Tree_Beats &other) noexcept
Swap this tree with other in O(1).
constexpr bool is_empty() const noexcept
True if the tree contains no elements.
void pull_up(size_t node) const
void fill_leaves_recursive(const size_t node, size_t start, size_t end, Getter &getter)
Segment_Tree_Beats & operator=(Segment_Tree_Beats &&other) noexcept(std::is_nothrow_move_assignable_v< Array< Node > >)
Exchange this tree with another, which is left with the previous elements of this one.
T query_sum_impl(size_t node, const size_t start, const size_t end, const size_t l, const size_t r) const
void init_leaf(size_t node, const T &val)
Segment_Tree_Beats(std::initializer_list< T > il)
Construct from an initializer list.
Segment_Tree_Beats(Segment_Tree_Beats &&other) noexcept(std::is_nothrow_move_constructible_v< Array< Node > >)
Take the elements of another tree, which is left empty.
Segment_Tree_Beats(const DynList< T > &values)
Construct from a DynList<T>.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
iterator begin() noexcept
Return an STL-compatible iterator to the first element.
A binary functor closed over T.
Binary operation compatible with Segment Tree queries.
Policy concept for lazy segment tree.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
std::decay_t< typename HeadC::Item_Type > T
and
Check uniqueness with explicit hash + equality functors.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
Range add + range max policy.
static constexpr T compose(const T &old_lazy, const T &new_lazy) noexcept
static constexpr T lazy_identity() noexcept
constexpr T value_identity() const noexcept
static constexpr T combine(const T &a, const T &b) noexcept
static constexpr T apply(const T &val, const T &delta, size_t) noexcept
Range add + range min policy.
static constexpr T lazy_identity() noexcept
static constexpr T compose(const T &old_lazy, const T &new_lazy) noexcept
constexpr T value_identity() const noexcept
static constexpr T apply(const T &val, const T &delta, size_t) noexcept
static constexpr T combine(const T &a, const T &b) noexcept
Range add + range sum policy.
static constexpr T value_identity() noexcept
static constexpr T combine(const T &a, const T &b) noexcept
static constexpr T apply(const T &val, const T &delta, size_t count) noexcept
static constexpr T lazy_identity() noexcept
static constexpr T compose(const T &old_lazy, const T &new_lazy) noexcept
Range assign + range sum policy.
static constexpr T combine(const T &a, const T &b) noexcept
static constexpr T value_identity() noexcept
static constexpr lazy_type lazy_identity() noexcept
std::pair< bool, T > lazy_type
static constexpr T apply(const T &val, const lazy_type &lz, size_t count) noexcept
static constexpr lazy_type compose(const lazy_type &old_lz, const lazy_type &new_lz) noexcept
Lazy segment tree for range add + range max.
Lazy segment tree for range add + range min.
Lazy segment tree for range add + range sum.
Max Segment Tree for range maximum queries with point updates.
Max_Segment_Tree(const size_t num, const T &init_val=std::numeric_limits< T >::lowest())
Construct with num elements, all equal to init_val.
Max_Segment_Tree(const DynList< T > &values)
Construct from a DynList<T>.
Max_Segment_Tree(const std::vector< T > &values)
Construct from a std::vector<T>.
Max_Segment_Tree(std::initializer_list< T > il)
Construct from an initializer list.
Max_Segment_Tree(const Array< T > &values)
Construct from an Array<T>.
Min Segment Tree for range minimum queries with point updates.
Min_Segment_Tree(const size_t num, const T &init_val=std::numeric_limits< T >::max())
Construct with num elements, all equal to init_val.
Min_Segment_Tree(const std::vector< T > &values)
Construct from a std::vector<T>.
Min_Segment_Tree(const DynList< T > &values)
Construct from a DynList<T>.
Min_Segment_Tree(const Array< T > &values)
Construct from an Array<T>.
Min_Segment_Tree(std::initializer_list< T > il)
Construct from an initializer list.
Sum Segment Tree for range sum queries with point updates.
Sum_Segment_Tree(const DynList< T > &values)
Construct from a DynList<T>.
Sum_Segment_Tree(const size_t num, const T &init_val=T())
Construct with num elements, all equal to init_val.
Sum_Segment_Tree(const std::vector< T > &values)
Construct from a std::vector<T>.
Sum_Segment_Tree(const Array< T > &values)
Construct from an Array<T>.
Sum_Segment_Tree(std::initializer_list< T > il)
Construct from an initializer list.
Dynamic array container with automatic resizing.
Alias for htlist.H (DynList implementation).
Sparse Table for static range queries in O(1).