Skip to content

Commit b154937

Browse files
committed
add min left now
1 parent c6e01cc commit b154937

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

library/data_structures_[l,r)/seg_tree.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ template<class T, class F> struct tree {
3232
return op(x, y);
3333
}
3434
#include "seg_tree_uncommon/max_right.hpp"
35+
#include "seg_tree_uncommon/min_left.hpp"
3536
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int min_left(int l, int r, const auto& f) {
2+
for (T x = unit; l < r;) {
3+
int u = r + n, v = __lg(min(u & -u, r - l));
4+
if (T y = op(s[(u - 1) >> v], x); f(y))
5+
r -= 1 << v, x = y;
6+
else l = r - (1 << v) + 1;
7+
}
8+
return l;
9+
}

library/data_structures_[l,r]/seg_tree.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ template<class T, class F> struct tree {
3939
return x;
4040
}
4141
#include "seg_tree_uncommon/max_right.hpp"
42+
#include "seg_tree_uncommon/min_left.hpp"
4243
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int max_right(int l, int r, const auto& f) {
2+
if (T x = s[r + n]; f(x))
3+
while (l < r) {
4+
int u = r + n, v = __lg(min(u & -u, r - l));
5+
if (T y = op(s[(u - 1) >> v], x); f(y))
6+
r -= 1 << v, x = y;
7+
else l = r - (1 << v) + 1;
8+
}
9+
return l;
10+
}

0 commit comments

Comments
 (0)