diff --git a/structure/segment-tree/lazy-segment-tree.hpp b/structure/segment-tree/lazy-segment-tree.hpp index 468209ec..1ca00072 100644 --- a/structure/segment-tree/lazy-segment-tree.hpp +++ b/structure/segment-tree/lazy-segment-tree.hpp @@ -116,8 +116,8 @@ struct LazySegmentTree { } template - int find_first(int l, const C& check) { - if (l >= n) return n; + optional find_first(int l, const C& check) { + if (l >= n) return nullopt; l += sz; for (int i = height; i > 0; i--) propagate(l >> i); S sum = m.e(); @@ -137,12 +137,12 @@ struct LazySegmentTree { } sum = m.op(sum, data[l++]); } while ((l & -l) != l); - return n; + return nullopt; } template - int find_last(int r, const C& check) { - if (r <= 0) return -1; + optional find_last(int r, const C& check) { + if (r <= 0) return nullopt; r += sz; for (int i = height; i > 0; i--) propagate((r - 1) >> i); S sum = m.e(); @@ -163,6 +163,6 @@ struct LazySegmentTree { } sum = m.op(data[r], sum); } while ((r & -r) != r); - return -1; + return nullopt; } }; diff --git a/structure/segment-tree/segment-tree.hpp b/structure/segment-tree/segment-tree.hpp index 67a74cd9..0a3e9d60 100644 --- a/structure/segment-tree/segment-tree.hpp +++ b/structure/segment-tree/segment-tree.hpp @@ -66,8 +66,8 @@ struct SegmentTree { S all_prod() const { return seg[1]; } template - int find_first(int l, const C& check) const { - if (l >= n) return n; + optional find_first(int l, const C& check) const { + if (l >= n) return nullopt; l += sz; S sum = m.e(); do { @@ -85,12 +85,12 @@ struct SegmentTree { } sum = m.op(sum, seg[l++]); } while ((l & -l) != l); - return n; + return nullopt; } template - int find_last(int r, const C& check) const { - if (r <= 0) return -1; + optional find_last(int r, const C& check) const { + if (r <= 0) return nullopt; r += sz; S sum = m.e(); do { @@ -109,6 +109,6 @@ struct SegmentTree { } sum = m.op(seg[r], sum); } while ((r & -r) != r); - return -1; + return nullopt; } };