Can someone please spot out the time consuming factors in my code for the question https://www.codechef.com/NOV17/problems/SEGPROD/ from Novembor Long Challenge and how to get AC in all 3 subtasks(where to optimize! :(). I tried a lot to optimize but this is the bare minimum thing that has to be calculated in order to reach to the final answer.

Here’s the link to my submission : https://www.codechef.com/viewsolution/16258320

I am getting TLE in one test file each of subtask 1 and 2… and TLE in the first 2 test files of subtask 3.

Thanks, in advance.