CodeForces Round #647 div2

problem:
Problem - B - Codeforces
my solution which gives me the correct ans:
X0yVGC - Online C++ Compiler & Debugging Tool - Ideone.com
in this above solution i use simple for loop to get the value of k.
But if i replace it with binary-search i am getting wrong output:
q0mqiO - Online C++ Compiler & Debugging Tool - Ideone.com
Please can anyone tell what mistake am i making

Yeah, if check is false why are you changing l=mid+1?

Your binary search would work only if for a certain value of K and above the statement held always true. (The statement was minimum K for which xor of K and every element s would return the same elements at the end)

As far as I am aware the above claim is not true.

2 Likes

Let say if your check is giving 0. Then l=mid+1 according to your code. But how can you say that k will be in other half ? Also, your code is giving wrong output for sample TC

2 Likes