If we represent the original array as a difference array, that is, $$$b_i = a_{i+1} - a_i$$$, then in the array $$$b$$$ we want to find the longest subsegment where the first half consists of 1s and the second half consists of -1s.
To find such a maximum subsegment, we will use a segment tree, where we will store the current answer, the maximum prefix for the answer, and the maximum suffix.
Then, to recalculate, we update the answer and also check if we can extend the prefix and suffix.
Changes in heights are just regular point updates in the segment tree.