No.2544 Many RMQ Problems
タグ : / 解いたユーザー数 52
作問者 :
Nachia
Problem Statement
Shirotsume found the following problem.
RMQ ProblemYou are given a permutation $p$ obtained by rearranging $(1, 2, \dots, N)$. Process the following $Q$ queries.
- Query $i$: Given a pair of integers $(L_i, R_i)$ satisfying $1 \leq L_i \leq R_i \leq N$, output the value of $\min(p_{L_i}, p_{L_i + 1}, \dots, p_{R_i})$.
Since this problem was a standard one for Shirotsume, he came up with the following problem.
Many RMQ ProblemsYou are given integers $N, Q$.
There are $\displaystyle N! \times \left ( \frac{N(N + 1)}{2} \right )^Q$ possible combinations of the values of $p$ and $L_i, R_i$ given in the input of RMQ Problem.
Find the sum of the values output when solving RMQ Problem for all of them, modulo $998244353$.
Solve Many RMQ Problems.
Constraints
- All inputs are integers.
- $1 \leq N, Q \leq 10^6$
Input
The input is given from standard input. The test case is given in the following format.
$N$ $Q$
Output
Output the answer.
Sample
Sample 1
Input
2 2
Output
48
There are $18$ possible inputs to RMQ Problem.
For example, for the input $p = (2, 1), (L_1, R_1) = (1, 2), (L_2, R_2) = (2, 2)$, the sum of the outputs is $\min(p_1, p_2) + \min(p_2) = 1 + 1 = 2$.
The sum of the answers over all possible inputs is $48$.
Sample 2
Input
3 3
Output
6264
Sample 3
Input
1 100
Output
100
Sample 4
Input
1000000 1000000
Output
519524455
Don't forget to find the remainder modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。