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/Doubling.java

Depends on

Verified with

Code

package library;

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

final class Doubling {
	public final int n;
	public final int log;
	public final int next[][];

	private Doubling(final int n, final long max) { // O(1)
		FastIO.nonNegativeCheck(n);
		FastIO.nonNegativeCheck(max);
		this.n = n;
		log = Long.numberOfTrailingZeros(Long.highestOneBit(max)) + 1;
		next = new int[log][n];
		Arrays.fill(next[0], -1);
	}
	// O(NlogM)
	public Doubling(final int n, final long max, final int[] edges) {
		this(n, max);
		System.arraycopy(edges, 0, next[0], 0, n);
		init();
	}
	public <Edge extends AbstractEdge<Edge>> Doubling(final int n, final long max, final AbstractNode<Edge> edges) {
		this(n, max);
		for(Edge e : edges) next[0][e.source] = e.target;
		init();
	}
	private final void init() {
		for(int k = 0; k + 1 < log; k ++) {
			for(int v = 0; v < n; v ++) {
				if(next[k][v] == -1) next[k + 1][v] = -1;
				else next[k + 1][v] = next[k][next[k][v]];
			}
		}
	}

	int cal(int x, final long q) { // O(logQ)
		FastIO.rangeCheck(x, n);
		FastIO.nonNegativeCheck(q);
		for(int k = log - 1; k >= 0; k --) {
			if(x == -1) break;
			if((q & 1l << k) != 0) x = next[k][x];
		}
		return x;
	}
}
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