def sign_of_sequence_fast(sequence: list) -> int:
    """
        Sign of sequence equals to (-1)**(sequence inversions).
        Sequence must contain elements from 0 to len(sequence).
    """
    sign = 1
    elements_to_check = [True for _ in range(len(sequence))]

    for i in range(len(sequence)):
        if elements_to_check[i]:
            current_element = sequence[i]
            while current_element != i:
                elements_to_check[current_element] = False
                sign = -sign
                current_element = sequence[current_element]

    return sign