A12674 | Submarine in the Rybinsk Sea (hard edition)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers $a_1, a_2, \dots, a_n$ .
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.
Let's denote a function that alternates digits of two numbers $f(a_1 a_2 \dots a_{p - 1} a_p, b_1 b_2 \dots b_{q - 1} b_q)$ , where $a_1 \dots a_p$ and $b_1 \dots b_q$ are digits of two integers written in the decimal notation without leading zeros.
In other words, the function $f(x, y)$ alternately shuffles the digits of the numbers $x$ and $y$ by writing them from the lowest digits to the older ones, starting with the number $y$ . The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.
For example: $$$$f(1111, 2222) = 12121212 $$ $$ f(7777, 888) = 7787878 $$ $$ f(33, 44444) = 4443434 $$ $$ f(555, 6) = 5556 $$ $$ f(111, 2222) = 2121212 $$ </p><p>Formally,</p><ul> <li> if $p \\ge q$ then $f(a\_1 \\dots a\_p, b\_1 \\dots b\_q) = a\_1 a\_2 \\dots a\_{p - q + 1} b\_1 a\_{p - q + 2} b\_2 \\dots a\_{p - 1} b\_{q - 1} a\_p b\_q$ ; </li><li> if $p < q$ then $f(a\_1 \\dots a\_p, b\_1 \\dots b\_q) = b\_1 b\_2 \\dots b\_{q - p} a\_1 b\_{q - p + 1} a\_2 \\dots a\_{p - 1} b\_{q - 1} a\_p b\_q$ . </li></ul><p>Mishanya gives you an array consisting of $n$ integers $a\_i$ , your task is to help students to calculate $\\sum\_{i = 1}^{n}\\sum\_{j = 1}^{n} f(a\_i, a\_j)$ modulo $998\\,244\\,353$$$.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.
Let's denote a function that alternates digits of two numbers $f(a_1 a_2 \dots a_{p - 1} a_p, b_1 b_2 \dots b_{q - 1} b_q)$ , where $a_1 \dots a_p$ and $b_1 \dots b_q$ are digits of two integers written in the decimal notation without leading zeros.
In other words, the function $f(x, y)$ alternately shuffles the digits of the numbers $x$ and $y$ by writing them from the lowest digits to the older ones, starting with the number $y$ . The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.
For example: $$$$f(1111, 2222) = 12121212 $$ $$ f(7777, 888) = 7787878 $$ $$ f(33, 44444) = 4443434 $$ $$ f(555, 6) = 5556 $$ $$ f(111, 2222) = 2121212 $$ </p><p>Formally,</p><ul> <li> if $p \\ge q$ then $f(a\_1 \\dots a\_p, b\_1 \\dots b\_q) = a\_1 a\_2 \\dots a\_{p - q + 1} b\_1 a\_{p - q + 2} b\_2 \\dots a\_{p - 1} b\_{q - 1} a\_p b\_q$ ; </li><li> if $p < q$ then $f(a\_1 \\dots a\_p, b\_1 \\dots b\_q) = b\_1 b\_2 \\dots b\_{q - p} a\_1 b\_{q - p + 1} a\_2 \\dots a\_{p - 1} b\_{q - 1} a\_p b\_q$ . </li></ul><p>Mishanya gives you an array consisting of $n$ integers $a\_i$ , your task is to help students to calculate $\\sum\_{i = 1}^{n}\\sum\_{j = 1}^{n} f(a\_i, a\_j)$ modulo $998\\,244\\,353$$$.
输入格式
The first line of the input contains a single integer $n$ ( $1 \le n \le 100\,000$ ) — the number of elements in the array. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 10^9$ ) — the elements of the array.
输出格式
Print the answer modulo $998\,244\,353$ .
输入输出样例
输入 #1
3 12 3 45
输出 #1
12330
输入 #2
2 123 456
输出 #2
1115598
输入 #3
1 1
输出 #3
11
输入 #4
5 1000000000 1000000000 1000000000 1000000000 1000000000
输出 #4
265359409
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted