You can also see the code in TopCoder Tutorial ,https://www.topcoder.com/community/competitive-programming/tutorials/range-minimum-query-and-lowest-common-ancestor/# ...