I failed to solve this question. can a python guru help me?

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

  1. update operation. take the XOR of all the bits in the bitmask from index l to r (both inclusive) with 1.
  2. 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.

Can you give a concrete source (like a link)?

Also, what exactly are you updating in the β€œupdate” operation?

1 Like