Kyopro Library
 
読み取り中…
検索中…
一致する文字列を見つけられません
monoid.hpp
[詳解]
1#pragma once
2#include"../../kyopro_library/template.hpp"
3
4/// @brief モノイド
5namespace Monoid {
6 /// @brief Minモノイド
7 /// @tparam max_value 単位元
8 template<typename T, T max_value=INF>
9 struct Min {
10 using Type=T;
11 static Type id() { return max_value; }
12 static Type op(const Type& a, const Type& b) { return min(a,b); }
13 };
14
15 /// @brief Maxモノイド
16 /// @tparam min_value 単位元
17 template<typename T, T min_value=-INF>
18 struct Max {
19 using Type=T;
20 static Type id() { return min_value; }
21 static Type op(const Type& a, const Type& b) { return max(a,b); }
22 };
23
24 /// @brief 和
25 template<typename T>
26 struct Sum {
27 using Type=T;
28 static Type id() { return 0; }
29 static Type op(const Type& a, const Type& b) { return a+b; }
30 };
31
32 /// @brief (和,区間の長さ)
33 template<typename T>
34 struct SumPair {
35 using Type=pair<T,int>;
36 static Type id() { return make_pair(T(0),0); }
37 static Type op(const Type& a, const Type& b) { return {a.first+b.first,a.second+b.second}; }
38 };
39}
モノイド
Definition monoid.hpp:5
Maxモノイド
Definition monoid.hpp:18
static Type id()
Definition monoid.hpp:20
static Type op(const Type &a, const Type &b)
Definition monoid.hpp:21
Minモノイド
Definition monoid.hpp:9
static Type id()
Definition monoid.hpp:11
static Type op(const Type &a, const Type &b)
Definition monoid.hpp:12
static Type id()
Definition monoid.hpp:28
static Type op(const Type &a, const Type &b)
Definition monoid.hpp:29
(和,区間の長さ)
Definition monoid.hpp:34
static Type id()
Definition monoid.hpp:36
static Type op(const Type &a, const Type &b)
Definition monoid.hpp:37
const int INF
Definition template.hpp:13