#P15276. [MCO 2025] Long Binary String

    ID: 15294 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2025Fibonacci 数列MCC/MCO(马来西亚)

[MCO 2025] Long Binary String

Description

A long binary string is formed via the following process:

  1. Start with the string 1\tt{1}.

  2. Every second, we replace each 1\tt{1} of the current string with 10\tt{10} and each 0\tt{0} of the current string with 1\tt{1}.

The state of the string in the first few seconds is as follows: 1,10,101,10110,101101011, 10, 101, 10110, 10110101.

Let ss be the string obtained at the end of the process after running it for 1010010^{100} seconds. You want to answer QQ queries of the following type: how many ones are there between the ll-th character and rr-th character (inclusive) of ss?

Input Format

The first line contains a single integer QQ (1Q3000001 \le Q \le 300\,000), denoting the number of queries.

The next QQ lines each contain two space-separated integers l,rl,r (1lr10181 \le l \le r \le 10^{18}), representing the queries.

Output Format

For each query, output the number of ones between the ll-th character and rr-th character (inclusive) of ss.

3
3 9
6 6
1 12
5
1
8

Hint

Note

One can show that the first 1212 characters of the string are 101101011011101101011011.

For the first query, there are 55 ones between the 3rd character and 9th character. The relevant substring is 11010111101011.

For the second query, there is 11 one between the 6th character and 6th character. The relevant substring is 11.

For the third query, there are 88 ones between the 1st character and 12th character. The relevant substring is 101101011011101101011011.

Scoring

Subtask 11 (77 points): Q=1Q = 1, r300000r \le 300\,000

Subtask 22 (1010 points): l=1l = 1, r300000r \le 300\,000

Subtask 33 (1313 points): r300000r \le 300\,000

Subtask 44 (2020 points): l=1l=1, rr is equal to the length of the string after some integer number of seconds.

Subtask 55 (1515 points): l=rl=r

Subtask 66 (1515 points): Q=1Q = 1

Subtask 77 (1010 points): r109r \le 10^9

Subtask 88 (1010 points): No additional constraints