You are given a cyclic array A having N numbers. In an AND round, each element of the array A is replaced by the bitwise AND of itself, the previous element, and the next element in the array. All operations take place simultaneously. Can you calculate A after K such AND rounds ?


The first line contains the number of test cases T (T <= 50).
There follow 2T lines, 2 per test case. The first line contains two space seperated integers N (3 <= N <= 20000) and K (1 <= K <= 1000000000). The next line contains N space seperated integers Ai (0 <= Ai <= 1000000000), which are the initial values of the elements in array A.


Output T lines, one per test case. For each test case, output a space seperated list of N integers, specifying the contents of array A after K AND rounds.


Sample Input:
3 1 
1 2 3 
5 100 
1 11 111 1111 11111 
Sample Output:
0 0 0 
1 1 1 1 1

hide comments
hemakshis: 2017-06-24 18:32:25

My first segment tree problem with A.C. in one go..yippie :)

akt_1998: 2017-06-06 20:52:34

sweet :)

and_roid: 2017-06-05 19:40:24

Segment Tree rocks!!

lord_poseidon: 2017-06-01 12:34:11

Accepted in one go, simple seg tree

yash_18: 2017-06-01 10:36:53

If solving with segment tree just take care what value you return if that segment does not lie in the range :D

sfialok98: 2017-05-28 12:01:12

AC finally...!!!
Did with segment tree...

xariniov9: 2017-05-26 10:48:19

Why the answer of first test case 0 0 0?

should not it be 0 0 2 ?

got it.. array is cyclic

Last edit: 2017-05-26 10:51:24
nabila ahmed: 2016-11-02 06:08:49

Very interesting problem. Solved with BIT :)

dwij28: 2016-08-22 17:30:29

I don't know about how others solved it but for me Segment Tree worked wonders, constant TLE and WA before that.

Last edit: 2016-08-22 17:30:42
praval_singhal: 2016-07-13 22:25:21

What a blunder i was committing. 0&A=a. :P finally AC

Added by:Varun Jalan
Time limit:0.625s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Resource:Own Problem, used for Codechef Snackdown