#P7122. Chino 与线段树
Chino 与线段树
Problem Description
Chino has just learned a data structure called the segment tree. However, she ran into a problem when writing a segment tree: she does not know how much space to allocate. She only knows that the number of leaf nodes is a positive integer within the range .
Chino defines as the maximum array index used by a segment tree with leaf nodes. She believes that if she knows
then she can figure out how much space she needs. So she asks you, the clever one, to help her.
Specifically, the pseudocode for building the segment tree is as follows:
$\begin{aligned} &\underline{\kern{300pt}}\\ &\mathbf{Function:}\ \text{Build a Segment Tree.}\\[-10pt] &\underline{\kern{300pt}}\\[-5pt] &\begin{array}{r|l} 1&\ \mathbf{function}\ \text{BuildSegmentTree}(x,l,r):\\ 2&\qquad \mathbf{if}\ (l \ne r)\ \mathbf{then}:\\ 3&\qquad\qquad m \gets \left\lfloor (l+r)/2 \right\rfloor\\ 4&\qquad\qquad \text{BuildSegmentTree}(2x,l,m)\\ 5&\qquad\qquad \text{BuildSegmentTree}(2x+1,m+1,r)\\ 6&\qquad \mathbf{end\ if}\\ 7&\ \mathbf{end\ function}\\ \end{array}\\[-13pt] &\underline{\kern{300pt}} \end{aligned}$
The maximum array index used by the segment tree is the maximum value of the parameter among all calls to after executing $\def\t#1{\text{#1}}\t{BuildSegmentTree}\left(1,1,n\right)$.
Input Format
The input has two lines.
The first line contains a positive integer ; the second line contains a positive integer . Their meanings are as described in the statement.
Output Format
Output one line containing one positive integer, which is your answer.
1
10
108
233333
666666
588544964910
1
1000000000000000000
1419691012023749904603586777179575510
Hint
Sample Explanation #1
For segment trees with leaf nodes, the maximum indices are , respectively. Summing them gives .
Test Point Constraints
This problem uses bundled testdata.
For all data, .
The specific limits for each subtask are shown in the table below:
| Subtask ID | Score | ||
|---|---|---|---|
| 1 | 10 | ||
| 2 | |||
| 3 | |||
| 4 | |||
| 5 | |||
| 6 | |||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 |
Translated by ChatGPT 5