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

建议使用的浏览器:

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

5921:Binary Indexed Tree

题目描述
Recently, Mr. Frog has learned binary indexed tree. Here is the code of adding t to the interval [1,x]:

void add (int x, int t ){
for (int i = x; i != 0; i -= i & (-i))
a[i] += t;
}


If Mr. Frog is required to add t to the interval [l,r], he will add(r,t), and then add(l - 1,-t).

The cost of an interval [l,r] is defined as the number of the “really changed point”. The “really changed point” is the point whose value is modified by the given code.

For example, in order to add 1 to the interval [6,6], Mr. Frog will add 1 to the interval [1,6] (a[6] and a[4] will be added by 1), and add -1 to the interval [1,5] (a[5] and a[4] will be added by -1).

As the result, a[6] will be added by 1, a[5] will be added by -1, and a[4] will be added by 0. a[6] and a[5] are “really changed point”, and the cost is 2.

Mr. Frog wants to calculate the sum of the cost of the interval [l,r]$\subseteq $  [1,n] where l and r are two integers. Help Mr. Frog solve the problem.
输入解释
The first line contains only one integer T ($T\leq 10000$), which indicates the number of test cases.

For each test case, it contains an integer n ($1\leq n\leq 10^{18}$).
输出解释
For each test case, output one line ”Case #x: y”, where x is the case number (starting from 1), y is the sum of the cost (modulo 1000000007).
输入样例
3
1
2
3
输出样例
Case #1: 1
Case #2: 4
Case #3: 10
来自杭电HDUOJ的附加信息
Recommend wange2014

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

源链接: HDU-5921

最后修改于 2020-10-25T23:26:44+00:00 由爬虫自动更新

共提交 0

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