DRANGE(TLE)

The question has very strict time linit.I ma getting TLE.

Question Link:- DRANGE Problem - CodeChef

My Solution :- CodeChef: Practical coding for everyone

Editorial:- DRANGE - Editorial - editorial - CodeChef Discuss

Here In the editorial there are 2 ways of solving.Though I have solved with The type given at first.
The second type has implemented I think Segment tree concept(I didn’t understand How to solve it).
Plz help me out if it could be solved by the type of first kind

Terima kasih dan salam kenal.
codechef Link

code Link