static int[] offline_minimum(int[] A, int[] E) {
	  int[] R = new int[A.length]; Arrays.fill(R, E.length);
	  int pre = 0;

	  // Initialize the collection of subsets.
	  for (int i = 0; i < E.length; ++i) {
	    for (int j = pre; j <= E[i]; ++j) {
	      R[A[j]] = i;
	    }
	    pre = E[i] + 1;
	  }

	  int[] ret = new int[E.length]; Arrays.fill(ret, -1);  // stores the answer
	  int[] set = new int[E.length + 1];  // the disjoint-set
	  iota(set, 0, set.length, 0);  // initializes the disjoint-set
	  for (int i = 0; i < A.length; ++i) {
	    if (find_set(set, R[i]) != E.length && ret[find_set(set, R[i])] == -1) {
	      ret[set[R[i]]] = i;
	      union_set(set, set[R[i]], set[R[i]] + 1);
	    }
	  }
	  return ret;
	}