#C13776. Deterministic Array Shuffling Simulator
Deterministic Array Shuffling Simulator
Deterministic Array Shuffling Simulator
You are given an array of integers along with an integer seed S for a pseudo‐random number generator and a series of queries. There are two types of queries:
- reset: Restore the array to its original configuration.
- shuffle: Produce a permutation of the array using a deterministic variation of the Fisher–Yates shuffle.
Deterministic Shuffling Details:
To ensure reproducibility across different languages, use the following custom pseudo‐random generator:
[ \text{Initialize } cur = S. ]
[ \text{For } i=0 \text{ to } n-1:]
[ j = i + (cur \bmod (n-i)), \quad cur = cur + 1, \quad \text{swap } a[i] \text{ with } a[j]. ]
The shuffle
operation should make a copy of the current array (which is maintained through reset
operations) and then apply the above procedure to generate and return a shuffled array. Note that the random generator is initialized only once at the beginning with the seed S and its state continues across multiple shuffle
queries.
Your task is to simulate these operations. For each query provided in the input, output the resulting configuration of the array as space‐separated integers on a new line.
inputFormat
The input is read from stdin
and has the following format:
- The first line contains an integer n, the number of elements in the array.
- The second line contains n space‐separated integers representing the array.
- The third line contains an integer S, the seed for the pseudo‐random generator.
- The fourth line contains an integer q, the number of queries.
- The following q lines each contain a query which is either
reset
orshuffle
.
outputFormat
For each query, output the resulting array configuration as a single line of space‐separated integers to stdout
.
3
1 2 3
1
3
reset
shuffle
reset
1 2 3
2 1 3
1 2 3
</p>