I asked this from the best coder of my college and he was totally clueless and so am I. This is the question: https://codeforces.net/problemset/problem/4/A. My approach is to use a segment tree of balanced binary search trees and then apply heavy-light decomposition and binary lifting but it gives wrong answer on test 1.