Tree problem BST

Here is a problem :http://codeforces.com/contest/675/problem/D

i read editorial and got how to do…

buut checked some solution(seg tree + RMQ):http://codeforces.com/contest/675/submission/17964060

can u any1 explain me this solution and suggest some problem on seg tree + RMQ