code: protected static <T> T[] invapply(T[] src, int[] perm) {
          T[] res = src.clone();
          for (int i = 0; i < src.length; i++)
              res[i] = src[perm[i]];
          return res;
      }
docs: apply the inverse of a permutation