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 http://ideone.com/dgM5y4

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.