Flipping Coins

#include <stdio.h>

long int n=0,temp,number_of_coins,number_of_inputs,bit_mask;
long int number_of_ones(long int i) //Return the number of bits set
{
   return __builtin_popcountl(i);
}
int main(void)
{
    long int ctr,lower,upper,length;
    int op;

    scanf("%ld %ld",&number_of_coins,&number_of_inputs);
    length = number_of_coins-1;
    for(ctr = 0 ; ctr < number_of_inputs;ctr++) //Main loop
    {
        scanf("%d %ld %ld",&op,&lower,&upper);
        bit_mask = ((1 << length-lower+1)-1) & ~((1 << length-upper)-1);

        if(op == 0)
        {   

            n ^= bit_mask ; //Toggle the bits in the range lower to upper

        }
        else
        {
            temp = n;
            temp &= bit_mask;
            printf("%ld\n",number_of_ones(temp)); //Print number of bits set
        }


    }



    return 0;

}

wats wrong with my code its giving WA.

Try this test case.