Sunday, June 12, 2022

Add By Permutation

 You're given an array of integers 

A and a permutation P, each of size N. Recall that a permutation of length N is an array where every element from 1 to N occurs exactly once.

The following operation is performed on the array K times:

  • For each index i (1iN), add APi to Ai simultaneously.

For example, if A=[2,6,1,7] and P=[3,1,4,2], after one operation A=[2+A3,6+A1,1+A4,7+A2]=[3,8,8,13].

Find the values of A modulo 998244353, after performing the above operation K times.

Input Format

  • The first line contains two space separated integers N and K.
  • The second line contains N space separated integers A1,A2,AN, the elements of the array A.
  • The third line contains N space separated integers P1,P2,PN, the elements of the permutation P.

Output Format

Print N space separated integers, the elements of the array A modulo 998244353 after performing the above operation K times.

Constraints

  • 1N,K2105
  • 1Ai<998244353
  • 1PiN
  • It is guaranteed that P is a permutation.

Sample Input 1 

4 3
2 6 1 7
3 1 4 2

Sample Output 1 

32 22 42 32

Explanation

The array A evolves as follows

  • A0=[2,6,1,7]
  • A1=[3,8,8,13]
  • A2=[11,11,21,21]
  • A3=[32,22,42,32]

where Ai denotes the array after i operations.

Thus, finally the elements of A read [32,22,42,32].

No comments:

Post a Comment

मुझे दिल में बसाना आसान नहीं....

पता है Recently i realised की मुझे दिल में बसाना आसान नहीं है बात-बात पे चिढ़ जाती हूं मैं दिल लगा लूं एक बार तो फिर ज़िद पे अड़...