This documentation is automatically generated by online-judge-tools/verification-helper
#include "Src/Algebra/Monoid/PrefixProductMonoid.hpp"
セグ木とかのモノイドで抽象化できるデータ構造に乗るやつ。
列 $A$ 上の区間 $[l, r)$ に対して
$g_{l, r}(A) = g(A_{l}, f(A_{l}, A_{l + 1}), f(A_{l}, A_{l + 1}, A_{l + 2}), \dots, f(A_{l}, A_{l + 1}, \dots, A_{r}))$ を管理する。
例えば $\max(A_{1}, A_{1} + A_{2}, \dots, A_{1} + A_{2} + \dots, A_{N})$ とか…
え?これ遅延伝搬いらないんすね。うお〜〜〜〜。
template <class Value>
class PrefixProductMonoidData(const Value& product, const Value& prefix)
template <class O, class F>
class PrefixProductMonoid
PrefixProductMonoidData
はproduct
, prefix
のゲッタだけ提供する。
product
は $f(A_{l}, A_{l + 1}, \dots, A_{r})$prefix
は $g_{l, r}(A)$PrefixProductMonoid
はElement, identity(), operation()
を提供するクラス。
テンプレート引数について、O
は $f$ 、 F
は $g$ のモノイドを与える必要がある。
#pragma once
#include <type_traits>
namespace zawa {
template <class Value>
class PrefixProductMonoidData {
Value product_{}, prefix_{};
public:
PrefixProductMonoidData() = default;
PrefixProductMonoidData(const Value& product, const Value& prefix)
: product_{product}, prefix_{prefix} {}
inline const Value& product() const noexcept {
return product_;
}
inline const Value& prefix() const noexcept {
return prefix_;
}
};
template <class O, class F>
class PrefixProductMonoid {
static_assert(std::is_same_v<typename O::Element, typename F::Element>);
public:
using Element = PrefixProductMonoidData<typename O::Element>;
static Element identity() noexcept {
return PrefixProductMonoidData{O::identity(), F::identity()};
}
static Element operation(const Element& l, const Element& r) noexcept {
return PrefixProductMonoidData{
O::operation(l.product(), r.product()),
F::operation(l.prefix(), O::operation(l.product(), r.prefix()))
};
}
};
} // namespace zawa
#line 2 "Src/Algebra/Monoid/PrefixProductMonoid.hpp"
#include <type_traits>
namespace zawa {
template <class Value>
class PrefixProductMonoidData {
Value product_{}, prefix_{};
public:
PrefixProductMonoidData() = default;
PrefixProductMonoidData(const Value& product, const Value& prefix)
: product_{product}, prefix_{prefix} {}
inline const Value& product() const noexcept {
return product_;
}
inline const Value& prefix() const noexcept {
return prefix_;
}
};
template <class O, class F>
class PrefixProductMonoid {
static_assert(std::is_same_v<typename O::Element, typename F::Element>);
public:
using Element = PrefixProductMonoidData<typename O::Element>;
static Element identity() noexcept {
return PrefixProductMonoidData{O::identity(), F::identity()};
}
static Element operation(const Element& l, const Element& r) noexcept {
return PrefixProductMonoidData{
O::operation(l.product(), r.product()),
F::operation(l.prefix(), O::operation(l.product(), r.prefix()))
};
}
};
} // namespace zawa