I was preparing for the test I got this question which I was not able to solve. How to solve these kinds of question:
Abhinav and charul are 2 friends traveling to a faraway place for ICPC, the biggest competition code completion. they decide to play a game. Abhibhav gives charul a bitmask. He tells charul that bitmask are very cool. According to him, A bitmask is a string. of binary bits (0 and 1s). for example β0111000β is a bitmask. anubhav is a naughty but brilliant computer scientist. he has given charul the following task:
Given a number N, Write a bitmask of length containing all 0s. now he gives Q operation. Each contains 2 number(l,r) as input. An operation can be one of the following
- update operation. take the XOR of all the bits in the bitmask from index l to r (both inclusive) with 1.
- query operation. count the number of the set bits in the bitmask between the index l to r (both inclusive)
He asked charul to find the sun of all the queries.