#P8577. [CoE R5] 暴龙的白菜

    ID: 9448 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>模拟洛谷原创O2优化前缀和洛谷月赛

[CoE R5] 暴龙的白菜

Background

The T-Rex loves eating Chinese cabbage.

Problem Description

You are given a string formed by concatenating, in order:

11 copy of 1\texttt{1}, 22 copies of 2\texttt{2}, 33 copies of 3\texttt{3}, 44 copies of 4\texttt{4}, 55 copies of 5\texttt{5}, 66 copies of 6\texttt{6}, 77 copies of 7\texttt{7}, 88 copies of 8\texttt{8}, 99 copies of 9\texttt{9}, 1010 copies of 10\texttt{10}, and so on.

For each query, find the sum of the digits from position ll to position rr in the string.

Input Format

The input contains multiple groups of testdata.

The first line contains a positive integer TT.

The next TT queries each contain two positive integers l,rl, r.

Output Format

Output TT lines, each containing one integer representing the answer.

4
5 9
46 50
114 514
19 19810
18
3
1134
74924

Hint

Sample Explanation

The string is:

$$\texttt{12233344445555566666677777778888888899999999910101010101010101010}\cdots\cdots$$

For the first query, the sum of the digits from position 55 to position 99 is 3+3+4+4+4=183+3+4+4+4=18.

For the second query, the sum of the digits from position 4646 to position 5050 is 1+0+1+0+1=31 + 0 + 1 + 0 + 1 = 3.


Constraints

This problem uses bundled tests.

  • Subtask 1(10 pts):T=1\texttt{Subtask 1(10 pts):}T=1, 1lr101\le l\le r\le 10;
  • Subtask 2(20 pts):1T10\texttt{Subtask 2(20 pts):}1\le T\le 10, 1lr1031\le l\le r\le 10^3;
  • Subtask 3(30 pts):1T103\texttt{Subtask 3(30 pts):}1\le T\le 10^3, 1lr1051\le l\le r\le 10^5;
  • Subtask 4(40 pts):\texttt{Subtask 4(40 pts):} no special constraints.

For 100%100\% of the data, 1T1051\le T\le 10^5, 1lr1061\le l\le r\le 10^6.

Translated by ChatGPT 5