Segment Tree Implementation of this problem(https://www.codechef.com/problems/FLIPCOIN)

I am new to segment trees and was trying this problem. After implementing the tree and getting correct answer on the given case, I submitted my solution (https://www.codechef.com/viewsolution/19033782) but it gave wrong answer.The same code gives correct answer on Hackerearth(https://rajasthan-hackathon.hackerearth.com/fr/problem/algorithm/problem-9-1/). Please point out if I am doing something wrong