#P9307. 「DTOI-5」进行一个排的重 (Maximum Version)
「DTOI-5」进行一个排的重 (Maximum Version)
Background
The difference between this problem and the Minimum Version is the required optimum (max/min) and the Constraints.
Xiao L is keen on reordering sequences to make them look neat.
Problem Description
Xiao L has a sequence of length , where each term 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 define $\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 , so that is maximized. Note that during reordering, each must be treated as a whole.
You need to compute the value of , and also 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
9 2
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&50&20 \operatorname{pts}\cr\hline \sf3&500&20 \operatorname{pts}\cr\hline \sf4&2\times 10^3&20 \operatorname{pts}\cr\hline \sf5&/&30 \operatorname{pts}\cr\hline \end{array}$$For of the testdata, , , and it is guaranteed that and are both permutations.
Translated by ChatGPT 5