#P3255. [JLOI2013] 地形生成

    ID: 2304 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp数学2013吉林组合数学

[JLOI2013] 地形生成

Description

Recently, IK has been working on terrain modeling. One stage of the work is to arrange several mountains in a line. Each mountain has a unique label and a height. To satisfy certain design requirements, each mountain is assigned a key number, requiring that for each mountain, the number of other mountains that are higher than it and placed before it must be less than its key number. Obviously, there can be many permutations that satisfy this requirement.

For every possible permutation, IK generates a corresponding label sequence and a height sequence. The label sequence is obtained by writing down the labels of the mountains in order.

The height sequence is obtained by writing down their heights in order. For example, if there are two mountains, and in one valid permutation the first mountain has label and height 11 and 33, and the second mountain has label and height 22 and 44, then the label sequence of this permutation is 11 22, and the height sequence is 33 44.

Now, given all the information about the mountains, IK wants to know how many different valid label sequences and height sequences there are in total.

Input Format

The first line contains the number of mountains NN. The next NN lines each contain two integers. In the order of labels from 11 to NN, they give the height and the key number of each mountain.

Output Format

Output two space-separated numbers. The first is the number of distinct label sequences, and the second is the number of distinct height sequences. Both answers should be taken modulo 20112011, that is, output the remainders of the two answers divided by 20112011.

2
1 2
2 2
2 2

Hint

Constraints: For all testdata, 1N10001 \leq N \leq 1000, and all numbers are positive integers not exceeding 10910^9.

Translated by ChatGPT 5