The basic idea was this -
Let A and C be numbers having odd number of ones in thier binary representation
Let B and D be numbers having even number of ones in thier binary representation
Then , A XOR C has even number of 1s A XOR B has odd number of 1s B XOR C has odd number of 1s B XOR D has even number of 1s
It means that when the parity of number of 1s is same, we get even numbers of 1s in XOR, but if parity is different, we get odd 1s in XOR
i solved this by keeping a flag array to find if the element is repeated then applied the logic that
xor of numbers with same parities has even parity else it has odd parity
Used a global map and a temprory vector, every time a new query comes check if it already exits, break loop if it does. Else insert new numbers that will be formed by xor of map elements and new number âxâ in a vector along with their parity which can be decided by parity of âxâ the new query and previous query increement odd or even accordingly.
I agree with you @srishab55, my solution in Java was failing task 5 and 7, link to the solution: Java Solution. I used fast reader and the approach given by author. Although with the same approach my c++ submission got AC for all tasks, link: c++ solution. If anyone can point out any issue with my java code please reply here.