Get predecessors and successors in the beginning instead of figuring them out for every single point separetely. This is still O(n), butt should be a lot quicker than the previous approach.