competitive-programming-java-library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub shun0923/competitive-programming-java-library

:heavy_check_mark: library/TemplateDualSegmentTree.java

Depends on

Verified with

Code

package library;

import java.util.function.*;
import library.FastIO;

class TemplateDualSegmentTree<T> {
	@FunctionalInterface
	interface BinaryConsumer<T> extends BiConsumer<T, T> {  }

	Supplier<T> e2Supplier;
	T e2;
	BinaryConsumer<T> g;

	int n;
	int height;
	T lazy[];
	int rangeL[];
	int rangeR[];

	// O(N)
	TemplateDualSegmentTree(T[] a, Supplier<T> e2Supplier, BinaryConsumer<T> g) {
		this(a.length, e2Supplier, g);
		System.arraycopy(a, 0, lazy, n, a.length);
	}
	TemplateDualSegmentTree(int len, Supplier<T> xSupplier, Supplier<T> e2Supplier, BinaryConsumer<T> g) {
		this(len, e2Supplier, g);
		for(int i = 0; i < len; i ++) lazy[i + n] = xSupplier.get();
	}
	@SuppressWarnings("unchecked")
	TemplateDualSegmentTree(int len, Supplier<T> e2Supplier, BinaryConsumer<T> g) {
		FastIO.nonNegativeCheck(len);
		this.e2Supplier = e2Supplier;
		this.e2 = e2Supplier.get();
		this.g = g;
		n = 1;
		height = 0;
		while(n < len) { n <<= 1; height ++; }
		lazy = (T[]) new Object[n << 1];
		for(int i = 0; i < lazy.length; i ++) lazy[i] = e2Supplier.get();
		rangeL = new int[n << 1];
		rangeR = new int[n << 1];
		for(int i = 0; i < n; i ++) { rangeL[i + n] = i; rangeR[i + n] = i + 1; }
		for(int i = n - 1; i > 0; i --) { rangeL[i] = rangeL[i << 1]; rangeR[i] = rangeR[(i << 1) + 1]; }
	}

	void eval(int k) { // O(1)
		if(!lazy[k].equals(e2)) {
			if(k < n) {
				g.accept(lazy[k << 1], lazy[k]);
				g.accept(lazy[(k << 1) + 1], lazy[k]);
				lazy[k] = e2Supplier.get();
			}
		}
	}

	void update(int l, int r, T val) { // O(logN)
		FastIO.inclusiveRangeCheck(l, n);
		FastIO.inclusiveRangeCheck(r, n);
		FastIO.assertion(l <= r, "l is larger than r.");
		l += n; r += n - 1;
		for(int i = height; i > 0; i --) { eval(l >> i); eval(r >> i); }
		r ++;
		while(l < r) {
			if((l & 1) != 0) { g.accept(lazy[l], val); eval(l); l ++; }
			if((r & 1) != 0) { r --; g.accept(lazy[r], val); eval(r); }
			l >>= 1; r >>= 1;
		}
	}

	T get(int j) { // O(logN)
		FastIO.inclusiveRangeCheck(j, n);
		j += n;
		for(int i = height; i > 0; i --) eval(j >> i);
		return lazy[j];
	}
}
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/site-packages/onlinejudge_verify/languages/user_defined.py", line 71, in bundle
    return subprocess.check_output(shlex.split(command))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.11.2/x64/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['false']' returned non-zero exit status 1.
Back to top page