#P6025. Segment Tree Array Index XOR
Segment Tree Array Index XOR
Segment Tree Array Index XOR
A standard segment tree is built on an interval of n leaves using a recursive algorithm. In this implementation, the tree is stored in an array with the root at index 1 and, for any node at index i, its left and right children are stored at indices 2*i and 2*i+1 respectively. Although only the nodes corresponding to segments are "useful", the recursion may cause the maximum array index used to be larger than the number of nodes.
Define f(n) to be the maximum array index used when building a segment tree for an interval with n leaves. It can be verified that:
- For the base case: \(f(1)=1\).
- If n is even, say \(n=2m\), then the recursive structure implies \[ f(2m)=2\cdot f(m)+1. \]
- If n is odd and \(n>1\), say \(n=2m+1\), then we have \[ f(2m+1)=2\cdot f(m+1). \]
Your task is to compute the following expression: \[ f(l) \oplus f(l+1) \oplus \cdots \oplus f(r), \] where \(\oplus\) denotes the bitwise XOR operation.
Note: It is guaranteed that \(1 \le l \le r\).
inputFormat
The input consists of one line containing two space-separated integers l and r.
\(1 \le l \le r\)
outputFormat
Output a single integer, the result of \(f(l) \oplus f(l+1) \oplus \cdots \oplus f(r)\).
sample
1 3
4