The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 399 Weeks Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
As a project for her arithmancy class, Hermoine has designed a magical plate which contains a sequence of N numbers which permutes according to a fixed permutation everyday. We denote the sequence of numbers on the ith day as A[i][1], A[i][2], ... A[i][N].
f[1],f[2]...f[N] is a fixed permutation of (1,2,..N). The sequence A[i+1][1],A[i+1][2],...A[i+1][N] is the result of applying the permutation f[1],f[2],..f[N] to the sequence A[i][1],A[i][2],...A[i][N]. See the sample input for clarity.
The arithmancy teacher has asked Hermoine to report the sequence of numbers that she started with. Hermoine has forgotten the original sequence. Ron wants to impress Hermoine because well, she's gorgeous! He knows the number of days K that have passed since the design of the magical plate, the current sequence of numbers and the fixed permutation f. He now wants to find out the original sequence of integers on the magical plate.
The first line of input contains a single integer T, the total number of test cases.
3*T lines follow, 3 corresponding to each test case.
The first line of each test case contains 2 space-seperated integers N,K.
The second line contains N space-seperated integers : A[K][1], A[K][2], ... A[K][N].
The third line also contains N space-seperated integers : f[1], f[2], ... f[N]. It is guaranteed that f[1],f[2],...f[N] is a permutation of (1,2,...N).
The output must consist of T lines, one corresponding to each test case.
Corresponding to each test case output in a single line N space-seperated integers : A[0][1], A[0][2], .. A[0][N].
It is trivial to note that the solution exists and is unique.
1 T
1 N
0 K N
1 A[K][i]
1 f[i] N
f[i] != f[j] for all i,j st 1 N.
Â
Input: 1 5 2 200 100 500 300 400 3 4 5 1 2 Output: 100 500 300 400 200
(100,500,300,400,200) -> (300,400,200,100,500) -> (200,100,500,300,400)
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll