Given an array, and there are Q queries of two types.
Type-1 : given l , r , val
Update a[i] = a[i] xor val where i = [l , r]
Type-2 : given l , r
Return sum of a[i] where i = [l , r]
Can it be solved by segment tree with lazy propagation?
ThankYou :)
Yea, it can be solved using segment tree + lazy propagation, the idea is to keep the count of bits for all the values in a range.
Xoring a range basically means swapping the count of 1 bits with the count 0 bits for each subrange in the segment tree if val has 1 bit at that position.
The query is solved by adding 2^(bit_position)*cnt[bit_position] for each bit position and for every subrange.
ex problem from a past CF contest: http://codeforces.net/problemset/problem/242/E c++ solution: https://github.com/Jaskamalkainth/Codeforces/blob/master/xor_on_segment.cpp
Thanks a lot! :)
IMPOSIBLE