rcpl

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

View the Project on GitHub ruthen71/rcpl

:heavy_check_mark: algebra/acted_monoid/acted_monoid_plus_affine.hpp

Depends on

Verified with

Code

#pragma once

#include "../monoid/monoid_affine.hpp"
#include "../monoid/monoid_plus.hpp"

template <class T> struct ActedMonoidPlusAffine {
    using MS = MonoidPlus<T>;
    using MF = MonoidAffine<T>;
    using S = typename MS::value_type;
    using F = typename MF::value_type;
    static constexpr S mapping(const F f, const S x, const int size) {
        return f.a * x + f.b * T(size);
    }
};
#line 2 "algebra/acted_monoid/acted_monoid_plus_affine.hpp"

#line 2 "algebra/monoid/monoid_affine.hpp"

template <class T> struct Affine {
    T a;
    T b;
    friend std::ostream& operator<<(std::ostream& os, const Affine& f) {
        return os << f.a << ", " << f.b;
    }
};

template <class T> struct MonoidAffine {
    using value_type = Affine<T>;
    static constexpr value_type operation(const value_type& f,
                                          const value_type& g) noexcept {
        // f(x) := ax + b, g(x) := cx + d
        // g(f(x)) = c(ax + b) + d = cax + cb + d
        return {g.a * f.a, g.a * f.b + g.b};
    }
    static constexpr value_type identity() noexcept { return {T(1), T(0)}; }
};
#line 2 "algebra/monoid/monoid_plus.hpp"

template <class T> struct MonoidPlus {
    using value_type = T;
    static constexpr T operation(const T& a, const T& b) noexcept {
        return a + b;
    }
    static constexpr T identity() noexcept { return T(0); }
    static constexpr T inverse(const T& a) noexcept { return -a; }
    static constexpr bool commutative = true;
};
#line 5 "algebra/acted_monoid/acted_monoid_plus_affine.hpp"

template <class T> struct ActedMonoidPlusAffine {
    using MS = MonoidPlus<T>;
    using MF = MonoidAffine<T>;
    using S = typename MS::value_type;
    using F = typename MF::value_type;
    static constexpr S mapping(const F f, const S x, const int size) {
        return f.a * x + f.b * T(size);
    }
};
Back to top page