def replace_subset(lo, hi, arr, new_values, unique_resort=False):
    """
    Replace a subset of a sorted arr with new_values. Can also ensure the resulting outcome is unique and sorted
    with the unique_resort option.

    :param lo:
    :param hi:
    :param arr:
    :param new_values:
    :param unique_resort:
    :return:
    """
    result = arr[:lo] + new_values + arr[hi + 1:]
    if unique_resort:
        result = sorted(set(result))
    return result