XOR of a subarray ( range of elements ) | Set 2 | Function to find XOR in a range from L to R ; Compute xor from arr [ 0 ] to arr [ i ] ; Process every query in constant time ; If L == 0 ; Driver code ; query [ ]
def find_Xor ( arr , query , N , Q ) : NEW_LINE INDENT for i in range ( 1 , N ) : NEW_LINE INDENT arr [ i ] = arr [ i ] ^ arr [ i - 1 ] NEW_LINE DEDENT ans = 0 NEW_LINE for i in range ( Q ) : NEW_LINE INDENT if query [ i ] [ 0 ] == 0 : NEW_LINE INDENT ans = arr [ query [ i ] [ 1 ] ] NEW_LINE DEDENT else : NEW_LINE INDENT ans = ( arr [ query [ i ] [ 0 ] - 1 ] ^ arr [ query [ i ] [ 1 ] ] ) NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT DEDENT def main ( ) : NEW_LINE INDENT arr = [ 3 , 2 , 4 , 5 , 1 , 1 , 5 , 3 ] NEW_LINE N = 8 NEW_LINE Q = 2 NEW_LINE query = [ [ 1 , 4 ] , [ 3 , 7 ] ] NEW_LINE find_Xor ( arr , query , N , Q ) NEW_LINE DEDENT main ( ) NEW_LINE