please explain the logic behind the code
Query bits proble,m
Hey @shivanshu12800
The code uses lazy propagation, which means delaying the update until the query asked for an updated answer.
Update function - if we know the answer of the left half and right half then answer of current answer would be
ans= left_answer * 2^(end-mid)+right_answer or
t[node] = (t[node * 2 + 1] * pow(2, en - mid, mod) % mod + t[node * 2 + 2]) % mod;
Similar for the query function , recursively ask for left and right sub answers and use for current answer.
To know if the current node is updated or not, maintain an array lz[], if the node is not updated we update the node as well as all it’s children.
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.