XOR Engine doubt

Please rectify this code…and tell where i gone wrong.

Bro Can you tell me what it will calculate:

what is c[i] symbolizing?

c[n] is the sequence after adding the query(b[q]) to the sequence a[n]… and after that getting the even and odd from the sequence c[n]

1 Like

can you specify even and odd ?

how are you counting the number of set bits for each element??

U need to realize that odd + odd = even; even + odd = odd; even + even = even

as in the number of set bits for each number

counting how many numbERS are even with count and odd numbers by odd…then print according to that

1 Like

The question is you have to print No. of elements with even no. of 1’s and odd no. 1’s.

->1’s in the binary representation of the number which is the result of XOR of the elements of two input arrays

U need to solve this problem in O(t(n+q))
We can achieve this by counting the set bits for each element using the __builtin_popcount() function

1 Like

maintain 4 variables aodd, aeven, qodd, qeven;
then if a num in a has even set bits ++aeven; and so on n+q times
then print aevenqeven+aoddqodd for no of elements with even and print aoddqeven + aevenqodd

1 Like

bro please read the problem again and dry run the test case on the paper then you will surely get what i am saying!

1 Like