Skip to content

Commit a8f81a9

Browse files
committed
add const and const_cast to atcoder::lazy_segtree
1 parent 8de49c6 commit a8f81a9

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

atcoder/lazysegtree.hpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ struct lazy_segtree {
4040
for (int i = 1; i <= log; i++) update(p >> i);
4141
}
4242

43-
S get(int p) {
43+
S get(int p) const {
4444
assert(0 <= p && p < _n);
4545
p += size;
4646
for (int i = log; i >= 1; i--) push(p >> i);
4747
return d[p];
4848
}
4949

50-
S prod(int l, int r) {
50+
S prod(int l, int r) const {
5151
assert(0 <= l && l <= r && r <= _n);
5252
if (l == r) return e();
5353

@@ -70,7 +70,7 @@ struct lazy_segtree {
7070
return op(sml, smr);
7171
}
7272

73-
S all_prod() { return d[1]; }
73+
S all_prod() const { return d[1]; }
7474

7575
void apply(int p, F f) {
7676
assert(0 <= p && p < _n);
@@ -109,10 +109,10 @@ struct lazy_segtree {
109109
}
110110
}
111111

112-
template <bool (*g)(S)> int max_right(int l) {
112+
template <bool (*g)(S)> int max_right(int l) const {
113113
return max_right(l, [](S x) { return g(x); });
114114
}
115-
template <class G> int max_right(int l, G g) {
115+
template <class G> int max_right(int l, G g) const {
116116
assert(0 <= l && l <= _n);
117117
assert(g(e()));
118118
if (l == _n) return _n;
@@ -138,10 +138,10 @@ struct lazy_segtree {
138138
return _n;
139139
}
140140

141-
template <bool (*g)(S)> int min_left(int r) {
141+
template <bool (*g)(S)> int min_left(int r) const {
142142
return min_left(r, [](S x) { return g(x); });
143143
}
144-
template <class G> int min_left(int r, G g) {
144+
template <class G> int min_left(int r, G g) const {
145145
assert(0 <= r && r <= _n);
146146
assert(g(e()));
147147
if (r == 0) return 0;
@@ -173,14 +173,14 @@ struct lazy_segtree {
173173
std::vector<F> lz;
174174

175175
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
176-
void all_apply(int k, F f) {
177-
d[k] = mapping(f, d[k]);
178-
if (k < size) lz[k] = composition(f, lz[k]);
176+
void all_apply(int k, F f) const {
177+
const_cast<lazy_segtree*>(this)->d[k] = mapping(f, d[k]);
178+
if (k < size) const_cast<lazy_segtree*>(this)->lz[k] = composition(f, lz[k]);
179179
}
180-
void push(int k) {
180+
void push(int k) const {
181181
all_apply(2 * k, lz[k]);
182182
all_apply(2 * k + 1, lz[k]);
183-
lz[k] = id();
183+
const_cast<lazy_segtree*>(this)->lz[k] = id();
184184
}
185185
};
186186

0 commit comments

Comments
 (0)