#P16267. [蓝桥杯 2026 省 Python B 组] 位数求和

    ID: 18287 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2026蓝桥杯省赛单调栈

[蓝桥杯 2026 省 Python B 组] 位数求和

Problem Description

Xiao Lan has recently been studying interval statistics problems.

Given a sequence a1,a2,…,ana_1, a_2, \dots, a_n of length nn, in the original problem, you need to compute

$$\sum_{l=1}^{n} \sum_{r=l}^{n} (r - l + 1) \max_{l \leq i \leq r} a_i$$

That is, for every interval [l,r][l, r] in the sequence, take the interval length (r−l+1)(r - l + 1) and the interval maximum max⁡l≤i≤rai\max_{l \leq i \leq r} a_i, multiply them, and sum the results over all intervals.

However, Xiao Lan feels that directly using the interval length is a bit monotonous, so he makes a small modification to this problem.

He defines a function f(x)f(x) to be the number of digits of the integer xx in its decimal representation. For example:

f(998244353)=9f(998244353) = 9,

f(799)=3f(799) = 3.

Now, for each interval [l,r][l, r], Xiao Lan no longer uses the interval length itself, but uses the number of digits of the interval length, f(r−l+1)f(r - l + 1). Therefore, he wants you to compute the value of the following expression:

$$\sum_{l=1}^{n} \sum_{r=l}^{n} f(r - l + 1) \max_{l \leq i \leq r} a_i$$

Since the answer may be very large, you only need to output the result modulo 998244353998244353.

Input Format

The input consists of two lines.

The first line contains a positive integer nn, representing the length of the sequence.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n, representing the given sequence.

Output Format

Output one line containing an integer, representing $\sum_{l=1}^{n} \sum_{r=l}^{n} f(r - l + 1) \max_{l \leq i \leq r} a_i$ modulo 998244353998244353.

5
1 2 3 4 5
55
10
1 2 3 4 5 6 7 8 9 10
395

Hint

Constraints

For 30%30\% of the testdata, n≤500n \leq 500.

For 60%60\% of the testdata, n≤3000n \leq 3000.

For all testdata, 1≤n≤5000001 \leq n \leq 500000, 1≤ai≤1091 \leq a_i \leq 10^9.

Translated by ChatGPT 5