Problem 3061 --Rikka with Segment Tree

3061: Rikka with Segment Tree

"
Time Limit $2$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $0$ 正确数量 $0$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签
Rikka is a master of data structures and Segment tree is Rikka's favorite data structure. This problem is a simple exercise about it.

Given a positive integer n, the segment tree on [1,n] can be built by a recursive process: Starting with [1,n], suppose the current interval is [l,r], the process recursively builds subtrees for [l,⌊l+r2⌋],[⌊l+r2⌋+1,r] until l=r.

For example, when n=5, there are 9 intervals on the segment tree: [1,1],[2,2],[3,3],[4,4],[5,5],[1,2],[4,5],[1,3],[1,5]

To explore the structure of segment trees, Rikka defines a magic function f(i,n) which represents the depth of node [i,i] on a segment tree on [1,n] (the depth of the root is defined as 1). For example, f(1,5)=f(2,5)=4,f(3,5)=f(4,5)=f(5,5)=3.

Now Rikka gives you two positive integers L,R(L≤R), and she wants you to calculate:
∑n=LR∑i=1n(f(i,n)×i)
The first line of the input contains a single integer T(1≤T≤1000), the number of test cases.

For each test case, the input contains a single line with two positive integers L,R(1≤L≤R≤1018).
For each test case, output a single line with a single integer, the answer. The answer may be very large, you only need to output the answer modulo 998244353.
5
4 4
1 4
1 10
1 100
1 1000
30
52
843
1236922
763123843

推荐代码 查看3061 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$ $ms]
内存最少[$ $KB]
第一AC
第一挑战

赛题来源/所属竞赛 2019 Multi-University Training Contest 9 N/A

竞赛编号 竞赛名称 竞赛时间 访问比赛