forked from jaichhabra/hactktoberfesttimebois2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayMod.py
53 lines (50 loc) · 1.71 KB
/
ArrayMod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Chef is really interested in the XOR operation. He wants to take a
sequence A0,A1,...,AN−1 and for each i from 0 to K−1 inclusive (in
this order, one by one), perform the following operation:
Let's denote a=Ai%N and b=A N−(i%N)−1 before this operation.
Change Ai%N to a⊕b, i.e. a XOR b
Since Chef is busy, he asked you to find the final sequence he
should get after performing these operations.
Input
- The first line of the input contains a single integer T denoting
the number of test cases. The description of T test cases follows.
- The first line of each test case contains two space-separated
integers N and K
- The second line contains N space-separated integers A0,A1,...,AN−1
Output
For each test case, print a single line containing N space-separated
integers ― the elements of the final sequence.
Example Input 1
22
12
Example Output 31
"""
def main():
for _ in range(int(input())):
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr1 = arr[::]
if (k//n) % 3 == 1:
for i in range(n//2):
arr[n-i-1], arr[i]=arr[i], arr[i] ^ arr[n-i-1]
if n%2 !=0:
arr[n//2] = 0
elif (k//n) % 3 == 2:
for i in range(n//2):
arr[i], arr[n-i-1] = arr[n-i-1], arr[i] ^ arr[n-i-1]
if n%2 !=0:
arr[n//2] = 0
else:
if n%2 !=0 and k > n//2:
arr[n//2] = 0
for i in range(k%n):
arr[i] = arr[i] ^ arr[n-i-1]
print(' '.join(map(str, arr)))
'''
for i in range(k):
arr1[(i%n)] = arr1[i%n] ^ arr1[(n-(i%n)-1)]
print(' '.join(map(str, arr1)))
'''
if __name__ == '__main__':
main()