Suppose I have a given array A. Now there are multiple operations of the form
reverse i,j // means reverse the array Ai..j inclusive
and
print i,j
Print the array Ai..j.
Example ,
A = 6 9 1 10 4 15 9
reverse 2,3
A = 6 1 9 10 4 15 9
reverse 3,6
A = 6 1 15 4 10 9 9
print 1,4
6 1 15 4
I have heard that it can be done by cartesian trees. So I have been reading the blog here But I still can't understand how we can do this using cartesian tree, what is the key and value should be and how we should implement ?