Have you learned something about segment tree? If not, don’t worry, I will explain it for you.
Segment Tree is a kind of binary tree, it can be defined as this:
- For each node u in Segment Tree, u has two values:
Lu and
Ru.
- If
Lu=Ru,
u is a leaf node.
- If
Lu≠Ru,
u has two children x and y,with
Lx=Lu,
Rx=?Lu+Ru2?,
Ly=?Lu+Ru2?+1,
Ry=Ru.
Here is an example of segment tree to do range query of sum.
Given two integers L and R, Your task is to find the minimum non-negative n satisfy that: A Segment Tree with root node‘s value
Lroot=0 and
Rroot=ncontains
a node u with
Lu=L and
Ru=R.
For each test, output one line contains one integer. If there is no such n, just output -1.