Queries on XOR of XORs of all subarrays | C # code for 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 program to test above function
using System ; class GFG { static void ansQueries ( int [ ] prefeven , int [ ] prefodd , int l , int r ) { if ( ( r - l + 1 ) % 2 == 0 ) Console . WriteLine ( "0" ) ; else { if ( l % 2 == 0 ) Console . WriteLine ( prefeven [ r ] ^ prefeven [ l - 1 ] ) ; else Console . WriteLine ( prefodd [ r ] ^ prefodd [ l - 1 ] ) ; } } static void wrapper ( int [ ] arr , int n , int [ ] l , int [ ] r , int q ) { int [ ] prefodd = new int [ 100 ] ; int [ ] prefeven = new int [ 100 ] ; for ( int 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 ] ; } } int j = 0 ; while ( j != q ) { ansQueries ( prefeven , prefodd , l [ j ] , r [ j ] ) ; j ++ ; } } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; int [ ] l = { 1 , 1 , 2 } ; int [ ] r = { 2 , 3 , 4 } ; int q = l . Length ; wrapper ( arr , n , l , r , q ) ; } }