Разработан Java-класс обобщённого дерева отрезков (Segment Tree) с поддержкой отложенных операций (lazy propagation).
// Создание дерева из массива
public SegmentTree(
T[] array,
Combiner<T> combiner,
Updater<T, U> updater,
LazyUpdater<U> lazyUpdater,
T neutral,
U noUpdate
)
// Создание дерева размера size
public SegmentTree(
int size,
Combiner<T> combiner,
Updater<T, U> updater,
LazyUpdater<U> lazyUpdater,
T neutral,
U noUpdate
)public T query(int l, int r)public void update(int l, int r, U value)@FunctionalInterface
public interface Combiner<T> {
T combine(T left, T right);
}@FunctionalInterface
public interface Updater<T, U> {
T apply(T current, U update, int length);
}@FunctionalInterface
public interface LazyUpdater<U> {
U compose(U existing, U newUpdate);
}