Here is the submission Solution: 49091773 | CodeChef . The problem looks quite easy(though its in medium category). I tried to optimise the code as much as i could. Pls help.

Thanks.

your code will give TLE coz TC=O(10^10) and the cout<<endl at line 10 can give format

error

this is because you are using the wrong method you are using brute-force method and it will give you TLE as n can be 10^5 and every query can also be of 10^5 roughly so if you iterate over this again and again your time complexity is O(n^2) which will give you TLE check time constraints of the question. The correct method here is range update and range query data structure. Try to study about segment tree or Fenwick tree you will get to know.