Query Bits Doubt

I know we have to do lazy range updates,I have seen code in discussion but i didn’t get what is the logic exactly used for integer formed
This is the question:-
You are given an n-bit integer (initially 0). There are Q queries. Each query is of following type:

0 L R: Set all the bits from Lth bit to Rth bit to zero.
1 L R: Set all the bits from Lth bit to Rth bit to one.
2 L R: Find the integer formed by the bits in range [L, R]. Answer all the queries of type 2. Indexing is 0-based. See the sample test case for clarity.

You will have to store result forming by 2 child nodes in the parent node. Very smartly you have to calculate that number.

To this input
3 6
1 0 1
2 0 2
0 1 1
2 1 1
1 2 2
2 0 2
first output should be 7 not 6?

Why?
It say set 0 -1 bit to 1
So you get 1 1 0
that’s 6
PS: start numbering from 0 from left side

I am confused with number of bits.

we have 3 bits(initially all 0) , we have 6 queries.
Q1 - set 0-1 bits to 1
0 0 0 becomes 1 1 0 (started from left)
Q2 - Print ans from bits 0 to 2
1 1 0 is 6.
Right??

ohh I misread the question .Thank you…

Great to understood now
You may mark the thread closed now. Please give a rating.

Sir I am unable to get how to form number plz just tell the logic with example ,I will write code by myself.

Please look at the function update in this.

Sir, I have seen code but i didn’t get logic behind code that is how number is getting formed.It will be great help if u will make me understand using some example.

How would you for number if i say concatenate 1001 and 001 ?
You will multiply first string with some power of 2 and then add second string in it right?
The same way you do with decimal numbers… Its just that.

1 Like

Thank u… I understood and finally got 100.

That’s great!!
Hit the like button and you may close the thread now

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.