Segment tree, divide and conquer

I am solving a problem of divide and conquer in codeforces Problem - D - Codeforces
and In this question I am using segment trees for finding no. of distinct elements in any range Submission #204650300 - Codeforces
. It is is still giving TLE can anyone explain what am I doing wrong here?