Shil and Crazy Operation
Practice
3.7 (65 votes)
Implementation
Open
Graph theory
Algorithms
Approved
Medium
Problem
68% Success 1947 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Shil likes to perform Crazy Operation on an array A1,A2,...AN.

Given an array A1,A2,...AN and permutation P1,P2, ..,PN, a Crazy Operation consists of two parts:

  1. Perform Operation Bi = Ai for every i in 1..N

  2. Perform Operation Ai = BPi for every i in 1..N. Here P is a permutation from 1 to N.

Shil asks you to print the resulting array A1, A2,...AN after doing Crazy Operation on it , T times.

Input format:
The first line of input consists of two integers N and T. The next line consists of N integers A1, A2,...AN. The next line consists of permutation P1,P2,...PN.

Output format:
Print the resulting A1,A2,...AN after doing Crazy operations on it T times.

Constraints:
1≤N≤105
1≤T≤1018
1≤Ai≤109

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
Medium
Points:30
8 votes
Tags:
MathematicsMediumOpenApprovedNumber Theory
Points:30
1 votes
Tags:
MediumCombinatoricsLinear AlgebraAlgorithmsMathematicsOpenApproved