HDU 5323 solve this interesting problem burst search, hdu5323
Link
Solve this interesting problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 511 Accepted Submission (s): 114
Problem DescriptionHave 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, Lx = Lu , Rx = running Lu + Ru2 failed ⌋ , Ly = direction Lu + Ru2 direction + 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 = n Contains a node u Lu = L And Ru = R .
InputThe input consists of several test cases.
Each test case contains two integers L and R, as described above.
0 ≤ L ≤ R ≤ 109
LR −l + 1 ≤ 2015
OutputFor each test, output one line contains one integer. If there is no such n, just output-1.
Sample Input
6 710 1310 11
Sample Output
7-112
Source2015 Multi-University Training Contest 3
For a given interval [l, r], build (1, n) using the recursive build method of the line tree and ask what the minimum n is, so that build (1, n) you can directly create the interval [l, r]. Train of Thought: Pay attention to the range. Then, you can estimate that the distance between the interval and the root node is no more than 10, so you can search from the bottom up.
Code
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.