当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6983:Segment Tree with Pruning

题目描述
Chenjb is struggling with data stucture now. He is trying to solve a problem using segment tree. Chenjb is a freshman in programming contest, and he wrote down the following C/C++ code and ran ''$\texttt{Node* root = build(1, n)}$'' to build a standard segment tree on range $[1,n]$:

Node* build(long long l, long long r) {
Node* x = new(Node);
if (l == r) return x;
long long mid = (l + r) / 2;
x -> lchild = build(l, mid);
x -> rchild = build(mid + 1, r);
return x;
}

Chenjb submitted his code, but unfortunately, got MLE (Memory Limit Exceeded). Soon Chenjb realized that his program will new a large quantity of nodes, and he decided to reduce the number of nodes by pruning:

Node* build(long long l, long long r) {
Node* x = new(Node);
if (r - l + 1 <= k) return x;
long long mid = (l + r) / 2;
x -> lchild = build(l, mid);
x -> rchild = build(mid + 1, r);
return x;
}

You know, Chenjb is a freshman, so he will try different values of $k$ to find the optimal one. You will be given the values of $n$ and $k$, please tell him the number of nodes that will be generated by his new program.
输入解释
The first line contains a single integer $T$ ($1 \leq T \leq 10\,000$), the number of test cases. For each test case:

The only line contains two integers $n$ and $k$ ($1 \leq k\leq n \leq 10^{18}$), denoting a query.
输出解释
For each query, print a single line containing an integer, denoting the number of segment tree nodes.
输入样例
3
100000 1
100000 50
1000000000000000000 1
输出样例
199999
4095
1999999999999999999

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6983

最后修改于 2021-10-23T19:10:54+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000/1000MS(Java/Others) 524288/524288K(Java/Others)