# Wrong answer in FLIPCOIN

I’m getting wrong answer can anybody please point out my mistake?

https://www.codechef.com/viewsolution/33639495

#include
using namespace std;
int arr[4100001] = {0};
bool lazy[4
100001] = {false};
#define left(x) (2x)
#define right(x) (2
x + 1)

void flipCoins(int l1,int r1,int l,int r,int idx){
if(lazy[idx]){
// This node needs to be updated
arr[idx] = (r1 - l1 + 1) - arr[idx]; // Update it
if(l1 != r1){
lazy[left(idx)] = !lazy[left(idx)]; // Mark child as lazy
lazy[right(idx)] = !lazy[right(idx)]; // Mark child as lazy
}
lazy[idx] = false; // Reset it
}
if(l1 > r || r1 < l) return;
else if(l <= l1 && r1 <= r){
arr[idx] = (r1 - l1 + 1) - arr[idx];
if(l1 != r1){
lazy[left(idx)]++;
lazy[right(idx)]++;
}
}
else{
int mid = (l1 + r1) / 2;
flipCoins(l1,mid,l,r,left(idx));
flipCoins(mid+1,r1,l,r,right(idx));
arr[idx] = arr[left(idx)] + arr[right(idx)];
}
}
int getcoins(int l1,int r1,int l,int r,int idx){
if(lazy[idx]){
// This node needs to be updated
arr[idx] = (r1 - l1 + 1) - arr[idx]; // Update it
if(l1 != r1){
lazy[left(idx)] = !lazy[left(idx)]; // Mark child as lazy
lazy[right(idx)] = !lazy[right(idx)]; // Mark child as lazy
}
lazy[idx] = false; // Reset it
}
if(l1 > r || r1 < l) return 0;
else if(l <= l1 && r1 <= r) return arr[idx];
else{
int mid = (l1 + r1) / 2 ;
return getcoins(l1,mid,l,r,left(idx)) + getcoins(mid+1,r1,l,r,right(idx));
}

}
int main() {
// your code goes here
int n,q,fq,a,b;
cin>>n>>q;
for(int i=0;i<q;i++){
cin>>fq>>a>>b;
a++,b++;
if(fq){
cout<<getcoins(1,n,a,b,1)<<endl;
}else{
flipCoins(1,n,a,b,1);
}
}
return 0;
}

I don’t know why but the link is not working for me…
Could you please format your code using blockquote or something

Thank you