@Test public void testRandomQueryAndSet2() { Random r = new Random(); int N = 500; Integer[] in = new Integer[N]; for (int i = 0; i < N; i++) in[i] = r.nextInt(N) * 2 - N; SegmentTree<Integer> maxTree = new SegmentTree<>(in, (a, b) -> Math.max(a, b), null, null); checkMax(in, maxTree); for (int j = 0; j < 5; j++) { for (int i = 0; i < N / 5; i++) { int k = r.nextInt(N); int val = r.nextInt(N) * 2 - N; in[k] = val; maxTree.set(k, val); } checkMax(in, maxTree); } }
public void set(int idx, E e) { if (idx < 0 || idx >= size) throw new IllegalArgumentException("idx invalid"); set(0, 0, size - 1, idx, e); }
SegmentTree { public void set(int idx, E e) { if (idx < 0 || idx >= size) throw new IllegalArgumentException("idx invalid"); set(0, 0, size - 1, idx, e); } }
SegmentTree { public void set(int idx, E e) { if (idx < 0 || idx >= size) throw new IllegalArgumentException("idx invalid"); set(0, 0, size - 1, idx, e); } SegmentTree(E[] data, Merger<E> function, Merger<E> extraMerger, Updater<E> extraUpdater); }
SegmentTree { public void set(int idx, E e) { if (idx < 0 || idx >= size) throw new IllegalArgumentException("idx invalid"); set(0, 0, size - 1, idx, e); } SegmentTree(E[] data, Merger<E> function, Merger<E> extraMerger, Updater<E> extraUpdater); E query(int st, int ed); void set(int idx, E e); void updateRange(int st, int ed, E e); @Override String toString(); }
SegmentTree { public void set(int idx, E e) { if (idx < 0 || idx >= size) throw new IllegalArgumentException("idx invalid"); set(0, 0, size - 1, idx, e); } SegmentTree(E[] data, Merger<E> function, Merger<E> extraMerger, Updater<E> extraUpdater); E query(int st, int ed); void set(int idx, E e); void updateRange(int st, int ed, E e); @Override String toString();  }