ContinueLib

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

View the Project on GitHub Continue765/ContinueLib

:heavy_check_mark: algebra/monoid.hpp

Depends on

Required by

Verified with

Code

#pragma once
#include <common.hpp>

template <typename Mono>
struct RevMono {
    using Type = typename Mono::Type;
    static Type e() {
        return Mono::e();
    }
    static Type op(const Type& a, const Type& b) {
        return Mono::op(b, a);
    }
};

template <typename T>
struct AddMono {
    using Type = T;
    static Type e() {
        return {0};
    }
    static Type op(const Type& a, const Type& b) {
        return {a + b};
    }
    static Type from(const i64& x) {
        return {x};
    }
    static Type inv(const Type& a) {
        return {-a};
    }
    static Type pow(const Type& a, i64 k) {
        return a * k;
    }
};

template <typename T>
struct MulMono {
    using Type = T;
    static Type e() {
        return {1};
    }
    static Type op(const Type& a, const Type& b) {
        return {a * b};
    }
    static Type from(const i64& x) {
        return {x};
    }
    static Type inv(const Type& a) {
        return T{1} / a;
    }
};

template <typename T>
struct MinMono {
    using Type = T;
    static Type e() {
        return {inf<T>};
    }
    static Type op(const Type& a, const Type& b) {
        return {min(a, b)};
    }
    static Type from(const i64& x) {
        return {x};
    }
    static Type pow(const Type& a, i64 k) {
        return (k == 0 ? e() : a);
    }
};

template <typename T>
struct MaxMono {
    using Type = T;
    static Type e() {
        return {-inf<T>};
    }
    static Type op(const Type& a, const Type& b) {
        return {max(a, b)};
    }
    static Type from(const i64& x) {
        return {x};
    }
    static Type pow(const Type& a, i64 k) {
        return (k == 0 ? e() : a);
    }
};

template <typename T>
struct GcdMono {
    using Type = T;
    static Type e() {
        return {0};
    }
    static Type op(const Type& a, const Type& b) {
        return {gcd(a, b)};
    }
    static Type from(const i64& x) {
        return {x};
    }
    static Type pow(const Type& a, i64 k) {
        return (k == 0 ? e() : a);
    }
};

template <typename T>
struct LcmMono {
    using Type = T;
    static Type e() {
        return {1};
    }
    static Type op(const Type& a, const Type& b) {
        return {lcm(a, b)};
    }
    static Type from(const i64& x) {
        return {x};
    }
    static Type pow(const Type& a, i64 k) {
        return (k == 0 ? e() : a);
    }
};

template <typename T>
struct XorMono {
    using Type = T;
    static Type e() {
        return {0};
    }
    static Type op(const Type& a, const Type& b) {
        return {a ^ b};
    }
    static Type inv(const Type& a) {
        return {a};
    }
    static Type power(const Type& a, i64 k) {
        return (k & 1) ? a : e();
    }
};
Back to top page