Getting TLE for hackerearth problem (Mr. Gora and his clever techniques)

I’m trying to solve this problem Problem link.
I am solving it offline using a segment tree that stores all node values. But unfortunately getting TLE for many times :frowning:

Solution link

Can anyone tell me any different approach or how should I do some optimisation?

1 Like