11 template<std::totally_ordered T>
15 auto it = std::lower_bound(v.cbegin(), v.cend(), value,
16 [](
const T &value,
const T &element) { return value <= element; });
23 template<std::
integral T>
26 if (vec.empty() || start >= end) {
31 auto lower = std::lower_bound(vec.begin(), vec.end(), start);
34 if (lower != vec.end() && *lower < end) {
41 template<
typename T, std::
integral I =
int>
62 I mid = low + (high - low) / 2;
66 }
else if (res < value) {
77 template<
typename T, std::
integral I =
int>
91 I count = high - low + 1;
99 if (comp(value, func(it))) {
110 template<
typename T, std::
integral I =
int>
124 template<
typename T, std::
integral I =
int>
138 I count = high - low + 1;
146 if (comp(func(it), value)) {
157 template<
typename T, std::
integral I =
int>
180 template<std::
integral T>
211 std::vector<int> compressed = nums;
212 std::sort(compressed.begin(), compressed.end());
213 compressed.erase(std::unique(compressed.begin(), compressed.end()), compressed.end());
215 auto func = [compressed](
int value) {
216 return std::lower_bound(compressed.begin(), compressed.end(), value) - compressed.begin();
219 int count = compressed.size();
220 return std::make_tuple(func, count);
Definition big_integer.hpp:14
std::optional< I > deferred_binary_search(I low, I high, const T &value, auto &&func)
Definition sorted_utils.hpp:57
static std::tuple< std::function< int(int)>, int > create_compression_mapper(const std::vector< int > &nums)
Definition sorted_utils.hpp:210
bool containsInRange(const std::vector< T > &vec, T start, T end)
Definition sorted_utils.hpp:25
I deferred_upper_bound(I low, I high, const T &value, auto &&func, auto &&comp)
Definition sorted_utils.hpp:89
int numOfGreaterElements(const std::vector< T > &v, T value)
Definition sorted_utils.hpp:12
void sortThree(T &a, T &b, T &c)
Definition sorted_utils.hpp:181
I deferred_lower_bound(I low, I high, const T &value, auto &&func, auto &&comp)
Definition sorted_utils.hpp:136