This documentation is automatically generated by online-judge-tools/verification-helper
View the Project on GitHub kmyk/competitive-programming-library
#include "monoids/plus_min_count_action.hpp"
#pragma once
#include <utility>
#include "../monoids/plus.hpp"
#include "../monoids/min_count.hpp"
/**
* @note lazy_propagation_segment_tree<min_count_monoid<T>, plus_monoid<T>, plus_min_count_action<T> > can count a number of zeros (or, non-zero numbers) in the array
*/
template <class T>
struct plus_min_count_action {
typename min_count_monoid<T>::value_type operator () (typename plus_monoid<T>::value_type f, typename min_count_monoid<T>::value_type x) const {
if (x.first == min_count_monoid<T>().unit().first) return x;
return std::make_pair(f + x.first, x.second);
}
};
#line 2 "monoids/plus_min_count_action.hpp"
#include <utility>
#line 2 "monoids/plus.hpp"
template <class T>
struct plus_monoid {
typedef T value_type;
value_type unit() const { return value_type(); }
value_type mult(value_type a, value_type b) const { return a + b; }
};
#line 2 "monoids/min_count.hpp"
#include <limits>
#line 4 "monoids/min_count.hpp"
template <class T>
struct min_count_monoid {
typedef std::pair<T, int> value_type;
value_type unit() const {
return std::make_pair(std::numeric_limits<T>::max(), 0);
}
value_type mult(value_type a, value_type b) const {
if (a.first < b.first) return a;
if (a.first > b.first) return b;
return std::make_pair(a.first, a.second + b.second);
}
static value_type make(T a) {
return std::make_pair(a, 1);
}
};
#line 5 "monoids/plus_min_count_action.hpp"
/**
* @note lazy_propagation_segment_tree<min_count_monoid<T>, plus_monoid<T>, plus_min_count_action<T> > can count a number of zeros (or, non-zero numbers) in the array
*/
template <class T>
struct plus_min_count_action {
typename min_count_monoid<T>::value_type operator () (typename plus_monoid<T>::value_type f, typename min_count_monoid<T>::value_type x) const {
if (x.first == min_count_monoid<T>().unit().first) return x;
return std::make_pair(f + x.first, x.second);
}
};