11#include < gtest/gtest.h>
22
3+ #include < cstddef>
34#include < mrpython/typical_segment_tree.hpp>
4- #include < numeric>
55#include < random>
66
77TEST (typical_segment_tree, min) {
@@ -30,14 +30,14 @@ TEST(typical_segment_tree, min) {
3030 }
3131}
3232
33- TEST (typicaL_segment_tree, fist_first_right ) {
33+ TEST (typicaL_segment_tree, find_first_right ) {
3434 std::mt19937_64 gen (std::random_device{}());
3535 std::size_t n = std::uniform_int_distribution<std::size_t >{1 , 5000 }(gen),
3636 q = std::uniform_int_distribution<std::size_t >{1 , 5000 }(gen);
3737 std::vector<int > a (n);
3838 std::uniform_int_distribution<int > val_dist (std::numeric_limits<int >::min (),
3939 std::numeric_limits<int >::max ());
40- std::uniform_int_distribution<std::size_t > size_dist (0 , n - 1 ),
40+ std::uniform_int_distribution<std::size_t > size_dist (0 , n),
4141 operator_dist (0 , 1 );
4242 std::generate (a.begin (), a.end (), [&] { return val_dist (gen); });
4343 mrpython::typical_segment_tree_min<int > tree (a.begin (), a.end ());
@@ -49,3 +49,24 @@ TEST(typicaL_segment_tree, fist_first_right) {
4949 EXPECT_EQ (tree.find_first_right (l, check), ans);
5050 }
5151}
52+
53+ TEST (typicaL_segment_tree, find_last_left) {
54+ std::mt19937_64 gen (std::random_device{}());
55+ std::size_t n = std::uniform_int_distribution<std::size_t >{1 , 5000 }(gen),
56+ q = std::uniform_int_distribution<std::size_t >{1 , 5000 }(gen);
57+ std::vector<int > a (n);
58+ std::uniform_int_distribution<int > val_dist (std::numeric_limits<int >::min (),
59+ std::numeric_limits<int >::max ());
60+ std::uniform_int_distribution<std::size_t > size_dist (0 , n),
61+ operator_dist (0 , 1 );
62+ std::generate (a.begin (), a.end (), [&] { return val_dist (gen); });
63+ mrpython::typical_segment_tree_min<int > tree (a.begin (), a.end ());
64+ while (q--) {
65+ std::size_t l = size_dist (gen) - 1 ;
66+ int tv = val_dist (gen);
67+ auto check = [tv](int x) { return x <= tv; };
68+ size_t ans = a.rend () - std::find_if (a.rend () - l - 1 , a.rend (), check) - 1 ;
69+ size_t out = tree.find_last_left (l, check);
70+ EXPECT_EQ (out, ans);
71+ }
72+ }
0 commit comments