forked from vinayakphegde/Generic-segment-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation.hpp
58 lines (52 loc) · 955 Bytes
/
operation.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef OPERATION_H
#define OPERATION_H
#include <climits>
template<typename T>
struct tree_node{
T value;
int index;
};
namespace operation
{
template<typename T>
class min
{
public:
static const T NEUTRAL_ELEMENT = INT_MAX;
tree_node<T> operator() (const tree_node<T>& lhs,const tree_node<T>& rhs) const
{
return (lhs.value<rhs.value) ? lhs : rhs;
}
};
template<typename T>
class max
{
public:
static const T NEUTRAL_ELEMENT = INT_MIN;
tree_node<T> operator() (const tree_node<T>& lhs,const tree_node<T>& rhs) const
{
return (lhs.value>rhs.value) ? lhs : rhs;
}
};
template<typename T>
class sum
{
public:
static const T NEUTRAL_ELEMENT = 0;
T operator()(const T& lhs,const T& rhs) const
{
return lhs+rhs;
}
};
template<typename T>
class gcd
{
public:
static const T NEUTRAL_ELEMENT = 0;
T operator()(const T& lhs,const T& rhs) const
{
return __gcd(lhs,rhs);
}
};
}
#endif