m1une's library

This documentation is automatically generated by online-judge-tools/verification-helper

View on GitHub

:heavy_check_mark: Multiply Monoid
(monoid/mul.hpp)

Overview

A monoid representing the multiplication operation. Useful for Range Product queries. Commonly used alongside modular arithmetic types (Modint) to prevent overflow.

Template Parameters

Properties

Interface and Complexity

This is a stateless algebra tag. Generic data structures use its public value_type, id(), and op(a, b) members. If the type also provides helpers such as make(...) or inv(x), they are described above or in the documented properties.

Each static operation runs in the cost of the underlying operation shown in the properties. Scalar monoids are $O(1)$; monoids whose value_type stores several items, permutations, or matrices scale with that stored size.

Verified with

Code

#ifndef M1UNE_MONOID_MUL_HPP
#define M1UNE_MONOID_MUL_HPP 1

namespace m1une {
namespace monoid {

// Monoid for multiplication (Range Product).
template <typename T>
struct Mul {
    using value_type = T;
    static constexpr bool commutative = true;

    // Returns the identity element for multiplication, which is 1.
    static constexpr T id() {
        return T(1);
    }

    // Returns the product of a and b.
    static constexpr T op(const T& a, const T& b) {
        return a * b;
    }
};

}  // namespace monoid
}  // namespace m1une

#endif  // M1UNE_MONOID_MUL_HPP
#line 1 "monoid/mul.hpp"



namespace m1une {
namespace monoid {

// Monoid for multiplication (Range Product).
template <typename T>
struct Mul {
    using value_type = T;
    static constexpr bool commutative = true;

    // Returns the identity element for multiplication, which is 1.
    static constexpr T id() {
        return T(1);
    }

    // Returns the product of a and b.
    static constexpr T op(const T& a, const T& b) {
        return a * b;
    }
};

}  // namespace monoid
}  // namespace m1une
Back to top page