Editorial for COCI '15 Contest 7 #3 Ozljeda
Submitting an official solution before solving the problem yourself is a bannable offence.
Firstly, let's notice that the first elements of the xorbonacci sequence are cyclically repeated throughout the entire sequence. In other words, it holds for every . The proof of this statement is left as an exercise to the reader.
Now we can recall some properties of the xor operation (labeled with ). More precisely, we are interested in the following properties:
Using these properties, we deduce that it holds:
Using the sequence's cyclicality from the first paragraph and the aforementioned properties, it is clear that the xor of the first elements of the xorbonacci sequence is equal to the xor of the first elements of the xorbonacci sequence where . Therefore, it is enough to preprocess the xors of the first elements and, using them, answer all given queries in .
Unveiling the explicit relation between and is left to you as an exercise.
Comments