How can i implement seg tree answer for this?

I was solving this problem from google kickstart round 2019 round B

In analysis section Its given to use seg tree but I didnt get how can i use here please help