#NOI2014E. 随机数生成器 (Random Number Generator)
随机数生成器 (Random Number Generator)
Description
Hacker is studying randomized algorithms recently. Randomized algorithms usually achieve randomness by calling random number generating (RNG) functions (such as random
in Pascal or rand
in C/C++). RNG functions are actually pseudo-random, with numbers created by certain algorithms.
For example, the quadratic congruential generator as stated below is a common algorithm:
Given non-negative integers , this algorithm calculates the recurrence as follows:
$$\forall i \geq 1, x_i = ( ax_{i-1}^2+bx_{i-1}+c ) \bmod d $$Therefore a sequence of non-negative integers of arbitrary length could be generated. In general, we regard this sequence as random.
Using a random sequence , we could also produce a random permutation from to according to the algorithm as follows:
- Initially set T as the increasing sequence of ;
- Perform swaps on , with the th one exchanging the value of and .
Hacker performs swaps in addition to the swaps. For the th additional swap, Hacker chooses two additional indices and and swaps the value of and .
To put the usefulness of the RNG algorithm to test, Hacker designs a problem:
Hacker begins with a chessboard of rows and columns. She starts with the process above, generating a random permutation of by swaps. Then the chessboard is filled by the numbers rowwise: that is, the number in the th row and th column is .
Then Hacker starts from the top-left corner of the board, namely the square in the first row and first column, and move right or down once at a time, without leaving the board, until reaching the bottom-right corner, or the square in the th row and th column.
Hacker records all numbers in passed squares and sorts them into increasing order. Therefore, for any valid route, Hacker could get a increasing sequence of length called sequence of route.
Hacker wants to know, what is the sequence of route with the smallest lexicographical order?
Input Format
The first line contains five integers, in order, describing the random seed of Hacker's RNG algorithm.
The second line contains three integers , indicating Hacker wants to generate a permutation of to fill in her chessboard with rows and columns and after the initial swaps, Hacker performs an additional swaps.
The th line in the next lines contains two integers , indicating the th additional swap exchanges the value of and .
Output Format
The output consists of one line of integers separated by spaces, representing the sequence of route with the smallest lexicographical order.
1 3 5 1 71
3 4 3
1 7
9 9
4 9
1 2 6 8 9 12
Constraints and Hint
The memory limit of this problem is , so please make sure the total memory use of submitted code does not exceed this limit. A -bit integer (such as int
in C/C++ or Longint
in Pascal) uses Bytes, so declaring a by array of -bit integers in the program will consume of memory.
For all the data, , , , , , .