FLIPCON with segment tree lazy propogation

I am trying to solve this qstn https://www.codechef.com/problems/FLIPCOIN.I thought lazy propagation of segment tree will work but I am getting wrong answer please check my approach and code


1)Initialize the array having all elements as tail arr[i]=1

2)Built the segment tree which count number of tail in a range

3)flip coin between range (a,b) ==>will update tree[si]=(b1-a1+1-tree[si]) where range[a1-b1] lies between (a,b)

{(query(a,b)=gives number of tail)}

4)find number of head therefore head=b-a+1-query(a,b);


This is what I’m getting when I execute your code
5 3
0 1 4
0 1 4
1 1 3