Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions structure/segment-tree/lazy-segment-tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ struct LazySegmentTree {
}

template <typename C>
int find_first(int l, const C& check) {
if (l >= n) return n;
optional<int> 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();
Expand All @@ -137,12 +137,12 @@ struct LazySegmentTree {
}
sum = m.op(sum, data[l++]);
} while ((l & -l) != l);
return n;
return nullopt;
}

template <typename C>
int find_last(int r, const C& check) {
if (r <= 0) return -1;
optional<int> 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();
Expand All @@ -163,6 +163,6 @@ struct LazySegmentTree {
}
sum = m.op(data[r], sum);
} while ((r & -r) != r);
return -1;
return nullopt;
}
};
12 changes: 6 additions & 6 deletions structure/segment-tree/segment-tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ struct SegmentTree {
S all_prod() const { return seg[1]; }

template <typename C>
int find_first(int l, const C& check) const {
if (l >= n) return n;
optional<int> find_first(int l, const C& check) const {
if (l >= n) return nullopt;
l += sz;
S sum = m.e();
do {
Expand All @@ -85,12 +85,12 @@ struct SegmentTree {
}
sum = m.op(sum, seg[l++]);
} while ((l & -l) != l);
return n;
return nullopt;
}

template <typename C>
int find_last(int r, const C& check) const {
if (r <= 0) return -1;
optional<int> find_last(int r, const C& check) const {
if (r <= 0) return nullopt;
r += sz;
S sum = m.e();
do {
Expand All @@ -109,6 +109,6 @@ struct SegmentTree {
}
sum = m.op(seg[r], sum);
} while ((r & -r) != r);
return -1;
return nullopt;
}
};
Loading