#P6025. 线段树
线段树
Description
Soon, Little W discovered that segment trees waste far too much space.
For example, a segment tree with looks like this:

You can see that only nodes store useful information, but the array indices used go up to .
Let be the maximum array index occupied by a segment tree with leaf nodes. Now Little W wants you to compute:
$$f(l)\;\oplus\;f(l+1)\;\oplus\;f(l+2)\;\oplus\cdots \oplus\;f(r)$$Here, denotes the bitwise XOR operation, which is the ^ operator in C++.
Input Format
One line with two integers , with the meaning described above.
Output Format
One line with one integer, the result.
6 6
13
Hint
Sample Explanation
, so the answer is .
Hint
If you do not know what a segment tree is:
void build(int k,int l,int r)
{
if(l==r)
{
//do something
//e.g. tree[k]=a[l]
return;
}
int mid=(l+r)>>1;
build(k<<1,l,mid);
build(k<<1|1,mid+1,r);
//do something
//e.g. tree[k]=tree[k<<1]+tree[k<<1|1]
}
In plain words: node corresponds to a segment . If , let . It has two children: the left child has index and segment ; the right child has index and segment . Then build the tree recursively on the child nodes.
After calling build(1,1,n), the segment tree is built. That is, node corresponds to segment .
Constraints
For of the testdata, .
For of the testdata, .
For of the testdata, , and the answer fits in long long.
Input Format
One line with two integers , with the meaning described above.
Output Format
One line with one integer, the result.
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号