3757. [noi2014] random number generator (Standard Io) Time limits: 5000 MS memory limits:262144 KB Description The first row of the input file contains five integers, which are x0, A, B, C, and D in sequence. This describes the Random Seed required by the random number generation algorithm for small h.
The row 2nd contains three integers, n, m, and Q, indicating that H wants to generate a one-to-n × M arrangement to fill in the chessboard of her n rows and M columns, in addition, after the initial n × m switching operation, the small h performs the Q additional switching operation.
In row Q, row I contains two integers, namely, UI, VI, which indicates that the values of t_ui and t_vi will be exchanged for the second additional exchange operation. Output outputs a row containing N + M − a positive integer separated by spaces, indicating the path sequence with the smallest Lexicographic Order. Sample input [Example input 1]
1 3 5 1 71
3 4 3
1 7
9 9
4 9
[Example input 2]
654321 209 111 23 70000001
10 10 0
[Example input 3]
123456 137 701 101 10000007
20 20 0
Sample output [sample output 1]
1 2 6 8 9 12
[Sample output 2]
1 3 7 10 14 15 16 21 23 30 44 52 70 72 88 94 95 97
[Sample output 3]
1 10 12 14 16 26 32 38 44 46 61 81 84 101 126 128 135 140 152 156 201 206 237 242 243 253 259 269 278 279 291 298 338 345 347 352 354 383 395
Data constraint should be relatively watery. The time limit of 5S can be passed by O (n2. Unfortunately, during the test, we only thought of generating a random series of 60 points and switching the process of generating an arrangement. The path must have the smallest Lexicographic Order, so you can do it with greed. From 1 to n * m, check whether these numbers are in the path. The range of desirable values for each selected number changes as follows. Use two arrays to maintain the upper and lower intervals of the numbers that can be selected as paths in each column. Change the values of the two arrays in the corresponding interval for each selected number.