#P9306. 「DTOI-5」进行一个排的重 (Minimum Version)
「DTOI-5」进行一个排的重 (Minimum Version)
Background
The difference between this problem and the Maximum Version is the extremum being asked for and the constraints.
Little L is keen on reordering sequences to make them look neat.
Problem Description
Little L has a sequence of length , where each item is a pair .
To make look neater, he specifies that and are both permutations of length .
To measure how neat is, he defines a weight function $f(a) = \displaystyle\sum_{i = 1}^n ([p_i > \max_{j = 1}^{i - 1} p_j] + [q_i > \max_{j = 1}^{i - 1} q_j])$. Note that when , both bracketed terms can take a value, because we consider $\displaystyle\max_{j = 1}^0 p_j = \displaystyle\max_{j = 1}^0 q_j = -\infty$.
To make look even neater, he decides to reorder in some way to obtain such that is minimized. Note that during reordering, you must treat as an indivisible whole.
He wants you to find the value of , and how many different can achieve .
Since the number of ways may be very large, you only need to output the result modulo .
Input Format
The first line contains an integer .
The second line contains integers .
The third line contains integers .
Output Format
Output one line with two integers, representing the required values.
5
1 5 2 4 3
1 4 2 5 3
3 48
Hint
Constraints
$$\def\or{\operatorname{or}} %\def\arrayscretch{1.5} \def\arraystretch{1.5} \begin{array}{|c|c|c|}\hline \textbf{Subtask}&n\le &\textbf{Points}\cr\hline \sf1&10&10 \operatorname{pts}\cr\hline \sf2&500&20 \operatorname{pts}\cr\hline \sf3&5\times10^3&20 \operatorname{pts}\cr\hline \sf4&10^5&20 \operatorname{pts}\cr\hline \sf5&5\times10^5&30 \operatorname{pts}\cr\hline \end{array}$$For of the testdata, , , and it is guaranteed that and are both permutations.
Translated by ChatGPT 5