@@ -0,0 +1,1111 @@
+package org.psjava.example;%0D%0A%0D%0Aimport junit.framework.Assert;%0D%0A%0D%0Aimport org.junit.Test;%0D%0Aimport org.psjava.ds.array.Array;%0D%0Aimport org.psjava.ds.array.MutableArrayFromValues;%0D%0Aimport org.psjava.ds.tree.segmenttree.RangeUpdatableSegmentTree;%0D%0Aimport org.psjava.ds.tree.segmenttree.RangeUpdatableSegmentTreeByLazyPropagation;%0D%0Aimport org.psjava.math.BinaryOperator;%0D%0A%0D%0Apublic class SegmentTreeWhichIsRangeUpdatableExample %7B%0D%0A%09@Test%0D%0A%09public void example() %7B%0D%0A%0D%0A%09%09// This is an advanced version of segment tree.%0D%0A%09%09// This updates in range in O(logn) time.%0D%0A%0D%0A%09%09Array%3CInteger%3E init = MutableArrayFromValues.create(1, 1, 1, 1, 1);%0D%0A%0D%0A%09%09RangeUpdatableSegmentTree%3CInteger%3E sumTree = RangeUpdatableSegmentTreeByLazyPropagation.create(init, new BinaryOperator%3CInteger%3E() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public Integer calc(Integer a, Integer b) %7B%0D%0A%09%09%09%09return a + b;%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A%0D%0A%09%09// Query by range.%0D%0A%0D%0A%09%09int sum1 = sumTree.query(0, 5);%0D%0A%09%09Assert.assertEquals(5, sum1);%0D%0A%0D%0A%09%09// Update range, this is done fast!%0D%0A%0D%0A%09%09sumTree.updateRange(1, 4, 100);%0D%0A%09%09int sum2 = sumTree.query(0, 5);%0D%0A%09%09Assert.assertEquals(302, sum2);%0D%0A%0D%0A%09%7D%0D%0A%7D%0D%0A

add an example