Queries on XOR of XORs of all subarrays | Output for each query ; If number of element is even . ; If number of element is odd . ; if l is even ; if l is odd ; Wrapper Function ; Evaluating prefixodd and prefixeven ; Driver code
function ansQueries ( prefeven , prefodd , l , r ) { if ( ( r - l + 1 ) % 2 == 0 ) document . write ( " " ) ; else { if ( l % 2 == 0 ) document . write ( prefeven [ r ] ^ prefeven [ l - 1 ] ) ; else document . write ( prefodd [ r ] ^ prefodd [ l - 1 ] ) ; } document . write ( " " ) ; } function wrapper ( arr , n , l , r , q ) { let prefodd = [ ] ; let prefeven = [ ] ; for ( let i = 1 ; i <= n ; i ++ ) { if ( ( i ) % 2 == 0 ) { prefeven [ i ] = arr [ i - 1 ] ^ prefeven [ i - 1 ] ; prefodd [ i ] = prefodd [ i - 1 ] ; } else { prefeven [ i ] = prefeven [ i - 1 ] ; prefodd [ i ] = prefodd [ i - 1 ] ^ arr [ i - 1 ] ; } } let i = 0 ; while ( i != q ) { ansQueries ( prefeven , prefodd , l [ i ] , r [ i ] ) ; i ++ ; } } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let n = arr . length ; let l = [ 1 , 1 , 2 ] ; let r = [ 2 , 3 , 4 ] ; let q = l . length ; wrapper ( arr , n , l , r , q ) ;