tree
The basic representation is a TreeMap from each run's start to a Pair containing the position just past the run's end and the value associated with that run. This is maintained in such a way that no runs overlap, no runs are empty, and there are no contiguous runs with equal values (they are automatically merged).