201265: [AtCoder]ARC126 F - Affine Sort

Memory Limit:1024 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $1100$ points

Problem Statement

Given is a sequence of $N$ positive integers $X = (X_1, X_2, \ldots, X_N)$.

For a positive integer $K$, let $f(K)$ be the number of triples of integers $(a,b,c)$ that satisfy all of the following conditions.

  • $1\leq c \leq K$.
  • $0\leq a < c$ and $0\leq b < c$.
  • For each $i$, let $Y_i$ be the remainder when $aX_i + b$ is divided by $c$. Then, $Y_1 < Y_2 < \cdots < Y_N$ holds.

It can be proved that the limit $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3}$ exists. Find this value modulo $998244353$ (see Notes).

Notes

We can prove that the limit in question is always a rational number. Additionally, under the Constraints of this problem, when that number is represented as $\frac{P}{Q}$ using two coprime integers $P$ and $Q$, we can prove that there is a unique integer $R$ such that $R\times Q\equiv P\pmod{998244353}$ and $0\leq R < 998244353$. Find this $R$.

Constraints

  • $2\leq N\leq 10^3$
  • $X_i$ are positive integers such that $\sum_{i=1}^N X_i \leq 5\times 10^5$.
  • $X_i\neq X_j$ if $i\neq j$.

Input

Input is given from Standard Input in the following format:

$N$
$X_1$ $X_2$ $\ldots$ $X_N$

Output

Print $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3}$ modulo $998244353$.


Sample Input 1

3
3 1 2

Sample Output 1

291154603
  • For example, when $(a,b,c) = (3,5,7)$, we have $Y_1 = 0$, $Y_2 = 1$, $Y_3 = 4$, which satisfy $Y_1 < Y_2 < Y_3$.
  • We have $f(1) = 0$, $f(2) = 0$, $f(3) = 1$, $f(4) = 2$, $f(5) = 5$.
  • We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = \frac{1}{24}$.

Sample Input 2

3
5 9 2

Sample Output 2

832860616

We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = \frac{55}{1008}$ .


Sample Input 3

2
2 3

Sample Output 3

166374059

We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = \frac{1}{6}$.


Sample Input 4

4
4 5 3 2

Sample Output 4

0

We have $\displaystyle \lim_{K\to\infty} \frac{f(K)}{K^3} = 0$.

Input

题意翻译

给定长度为 $N$ 的正整数序列 $X_1,X_2,\cdots,X_n$。 对于正整数 $K$,$F(K)$ 表示满足以下条件的三元组 $(a,b,c)$ 的个数: - $c\in[1,K],a,b\in[0,c)$。 - $aX_i+b$ 模 $c$ 单调递增。 求 $\lim\limits_{K\to \infty}\frac{F(K)}{K^3} \bmod 998244353$。 translated by syzf2222

加入题单

算法标签: