#P6025. 线段树

线段树

Description

Soon, Little W discovered that segment trees waste far too much space.

For example, a segment tree with n=6n=6 looks like this:

You can see that only 1111 nodes store useful information, but the array indices used go up to 1313.

Let f(n)f(n) be the maximum array index occupied by a segment tree with nn 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, \oplus denotes the bitwise XOR operation, which is the ^ operator in C++.

Input Format

One line with two integers l,rl, r, with the meaning described above.

Output Format

One line with one integer, the result.

6 6

13

Hint

Sample Explanation

f(6)=13f(6)=13, so the answer is 1313.

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 kk corresponds to a segment [l,r][l,r]. If lrl\neq r, let mid=l+r2mid=\lfloor\dfrac{l+r}2\rfloor. It has two children: the left child has index 2k2k and segment [l,mid][l,mid]; the right child has index 2k+12k+1 and segment [mid+1,r][mid+1,r]. Then build the tree recursively on the child nodes.

After calling build(1,1,n), the segment tree is built. That is, node 11 corresponds to segment [1,n][1,n].

Constraints

For 10%10\% of the testdata, 1lr1031\le l\le r\le10^3.
For 40%40\% of the testdata, 1lr1061\le l\le r\le 10^6.
For 100%100\% of the testdata, 1lr10151\le l\le r\le10^{15}, and the answer fits in long long.

Input Format

One line with two integers l,rl, r, with the meaning described above.

Output Format

One line with one integer, the result.

Hint

Translated by ChatGPT 5