#BS0000192. Dãy chữ số – phiên bản khó (Numerical Sequence, Hard Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Dãy chữ số – phiên bản khó (Numerical Sequence, Hard Version)
Numerical Sequence (Hard Version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An infinite string of digits is formed by concatenating blocks 1, 12, 123, 1234, ... . Block is obtained by concatenating decimal representations of the integers from through , without spaces.
The infinite string begins with 112123123412345.... Individual digits, rather than whole integers, are indexed starting at .
Answer independent queries: for each position , output the single digit at that position. In this hard version, can be as large as , so explicit generation is infeasible.
Input
- First line: integer .
- Each of the next lines contains one query position .
Output
- Print one decimal digit per query, each on its own line.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
1
3
20
38
56
Output
1
2
5
2
0
Explanation
The first six blocks are 1, 12, 123, 1234, 12345, 123456 with lengths . Their cumulative length is .
| Position | Digit | Reason |
|---|---|---|
| 1 | 1 | Only digit in block 1 |
| 3 | 2 | Second digit of block 2 |
| 20 | 5 | Fifth digit of block 6 |
| 38 | 2 | Found from block-length prefixes |
| 56 | 0 | Last digit of 10 at the end of block 10 |
Large positions are handled arithmetically, without building the string.