120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/lazy_segtree.rb', line 120
def range_apply(l, r, f)
return if l == r
l += @size
r += @size
@log.downto(1) do |i|
push(l >> i) if (l >> i) << i != l
push((r - 1) >> i) if (r >> i) << i != r
end
l2 = l
r2 = r
while l < r
(all_apply(l, f); l += 1) if l.odd?
(r -= 1; all_apply(r, f)) if r.odd?
l >>= 1
r >>= 1
end
l = l2
r = r2
1.upto(@log) do |i|
update(l >> i) if (l >> i) << i != l
update((r - 1) >> i) if (r >> i) << i != r
end
end
|