#P3962. [TJOI2013] 数字根
[TJOI2013] 数字根
Description
The digital root of a number is defined as repeatedly summing its digits until the result is less than 10. For example, the digital root of 64357 is 7, because , and . The digital root of an interval is defined as the digital root of the sum of all numbers in that interval.
Given a sequence , you need to answer several queries. For each query, you are given an interval . Among all contiguous subintervals within , find the top 5 distinct digital roots. If there are fewer than 5, fill the remaining positions with .
Input Format
- The first line contains an integer , the length of the sequence.
- The second line contains integers ().
- The third line contains an integer , the number of queries.
- Each of the next lines contains two integers (), denoting a query interval.
Output Format
Output lines. For each query interval, output the top 5 distinct digital roots of all its contiguous subintervals in descending order, space-separated. If there are fewer than 5, pad with .
5
101 240 331 4 52
3
1 3
4 5
1 5
8 7 6 4 2
7 4 2 -1 -1
9 8 7 6 4
Hint
Sample Explanation
For the first query interval , its contiguous subintervals are , , , , , . Their corresponding digital roots are . Therefore, the top 5 are .
Constraints
- 30% of the testdata: , .
- 100% of the testdata: , .
Translated by ChatGPT 5
京公网安备 11011102002149号