flipping coin TLE..??

I am using O(q(b-a)lgn) algo(BIT) still the tle comes up. how to improve on that .I am guessing its need to solved as range update and range query prob but still could anyone provide me with the apprach how to improve my code dgM5y4 - Online C Compiler & Debugging Tool - Ideone.com

Your solution is not optimized. You are counting the values in the queried range and hence it would give a TLE. You have to modify the BIT in order to answer range queries in O(log(N)) instead of N*log(N) which you are doing now.