So I was thinking about this CSES problem: link. I saw that the answer is (x-1) ^ (y-1), but I have absolutely no idea why it works. Could someone explain or at least give some hints? Thanks.
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 3 | Proof_by_QED | 147 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 142 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| Name |
|---|



(forgive my poor English)
This can be proved with induction .
Now we calculate the answer for $$$(x,y)$$$
Assume that we already know that the answer is $$$(tx-1)xor(y-1)$$$ for $$$(tx,y),tx \lt x$$$ and $$$(ty-1)xor (x-1)$$$ for $$$(x,ty),ty \lt y$$$ .
(make $$$x\leftarrow x-1,y\leftarrow y-1$$$)
What we need to prove is that $$$Mex(tx\ xor\ y,ty\ xor\ x )=x\ xor\ y$$$
We can see that $$$x\ xor\ y$$$ is not in $$${tx\ xor\ y,ty\ xor\ x}$$$ , so we only need to prove that for all $$$k\in[0,x\ xor\ y)$$$ , $$$k$$$ can be represented as $$$tx\ xor\ y$$$ or $$$ty\ xor\ x$$$ which is same as $$$k\ xor\ x \lt y$$$ or $$$k\ xor\ x \lt y$$$
We will prove that it is impossible for $$$k\in[0,x\ xor\ y)$$$ to satisfy $$$k\ xor\ x\geq y$$$ and $$$k\ xor\ x\geq y$$$
We can remove the equal sign.
The restriction becomes $$$k\ xor\ x \gt y$$$ and $$$k\ xor\ y \gt x$$$
Consider the first bit where $$$x\ xor\ k$$$ and $$$y$$$ differs .
It can be found that for all bits higher than this bit $$$k=x\ xor\ y$$$
And in this bit $$$y=0,x\ xor\ k=1$$$
And it is impossible for $$$x=0,k=1$$$ as it will break the limit of $$$k\in[0,x\ xor\ y)$$$ . So this must be $$$x=1,k=0$$$ , but in this way $$$k\ xor\ y$$$ and $$$x$$$ will differ at this bit and $$$k\ xor y=0,x=1$$$ , which will break the limit $$$k\ xor\ y \gt x$$$.
So it is impossible for $$$k\in[0,x\ xor\ y)$$$ to satisfy $$$k\ xor\ x\geq y$$$ and $$$k\ xor\ x\geq y$$$.
So $$$Mex(tx\ xor\ y,ty\ xor\ x )=x\ xor\ y$$$