Xorbonacci
Time limit1sMemory limit64 MB
Given the first K terms of an XOR recurrence, answer many queries asking for the XOR of terms l through r with indices up to 1e18.
- Level
Medium6 of 10
- Topics
- Math, Prefix sum, Bit manipulation
- Solved
- No attempts yet
Problem
Marin swung a racket at flies so hard that he hurt his elbow. His grandmother told him to rub herbs on it and the doctor prescribed a painkiller, but Marin ignored both and went looking for an answer in integer sequences.
He built a new sequence and named it the xorbonacci sequence. Its th term is written , and it is defined like this.
- when
Marin says the pain goes away once someone answers his queries. Each query gives two numbers and , and its answer is
Here is the bitwise XOR operation.
Input
The first line contains the integer ().
The second line contains the first terms of the xorbonacci sequence. Every value is a nonnegative integer smaller than .
The third line contains the integer ().
The th of the next lines contains two integers and () describing the th query.
Output
Print lines. The th line holds the answer to the th query of the input.