fork download
  1. import java.io.DataInputStream;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6.  
  7. class ANDROUND {
  8. static int a[];
  9. public static void main(String[] args) throws IOException {
  10. // TODO Auto-generated method stub
  11. Reader ir = new Reader();
  12. int t = ir.nextInt();
  13. StringBuilder sb = new StringBuilder();
  14. while (t-- > 0) {
  15. int n = ir.nextInt();
  16. int k = ir.nextInt();
  17. a = new int[n+1];
  18. // int b[] = new int[n];
  19. k=k<n?k:n;
  20. for (int i = 1; i <= n; i++) {
  21. a[i] = ir.nextInt();
  22.  
  23. }
  24. Segment_Tree st=new Segment_Tree(1,n);
  25. for(int i=1;i<= n ;i++){
  26. int s=(i-k+n)%n;
  27. int e=(i+k)%n;
  28. if(s==0)s=n;
  29. if(e==0)e=n;
  30. int res=-1;
  31. if(s<i)
  32. res&=st.query(s, i).value;
  33. else res&= st.query(s, n).value & st.query(1, i).value;
  34. if(e>i)res&= st.query(i, e).value;
  35. else res &= st.query(1, e).value & st.query(i,n).value;
  36. sb.append(res+" ");
  37. //System.out.println(res);
  38. }
  39. sb.append("\n");
  40.  
  41. }
  42.  
  43. pr.write(sb.toString());
  44. pr.flush();
  45. }
  46. static class Segment_Tree{
  47. int start, end, value;
  48. Segment_Tree left_child,right_child;
  49. public Segment_Tree(int a,int b){
  50. start=a;
  51. end=b;
  52. if(start!=end){
  53. int mid=(start+end)>>1;
  54. left_child=new Segment_Tree(a, mid);
  55. right_child=new Segment_Tree(mid+1, b);
  56. join(this, left_child, right_child);
  57. }
  58. else this.value=ANDROUND.a[start];
  59. }
  60. public Segment_Tree(){}
  61. public void join(Segment_Tree parent,Segment_Tree left_child,Segment_Tree right_child){
  62. parent.value=left_child.value&right_child.value;
  63. }
  64. public Segment_Tree query(int a,int b){
  65. if(start==a && end==b){
  66. return this;
  67. }
  68. int mid=(start+end)>>1;
  69. if(a>mid)return right_child.query(a, b);
  70. else if(b<=mid)return left_child.query(a, b);
  71. Segment_Tree ans=new Segment_Tree();
  72. join(ans,left_child.query(a,mid),right_child.query(mid+1, b));
  73. return ans;
  74. }
  75. }
  76. static class Reader {
  77. final private int BUFFER_SIZE = 1 << 16;
  78. private DataInputStream din;
  79. private byte[] buffer;
  80. private int bufferPointer, bytesRead;
  81.  
  82. public Reader() {
  83. din = new DataInputStream(System.in);
  84. buffer = new byte[BUFFER_SIZE];
  85. bufferPointer = bytesRead = 0;
  86. }
  87.  
  88. public Reader(String file_name) throws IOException {
  89. din = new DataInputStream(new FileInputStream(file_name));
  90. buffer = new byte[BUFFER_SIZE];
  91. bufferPointer = bytesRead = 0;
  92. }
  93.  
  94. public String readLine() throws IOException {
  95. byte[] buf = new byte[64];
  96. int cnt = 0, c;
  97. while ((c = read()) != -1) {
  98. if (c == '\n')
  99. break;
  100. buf[cnt++] = (byte) c;
  101. }
  102. return new String(buf, 0, cnt);
  103. }
  104.  
  105. public int nextInt() throws IOException {
  106. int ret = 0;
  107. byte c = read();
  108. while (c <= ' ')
  109. c = read();
  110. boolean neg = (c == '-');
  111. if (neg)
  112. c = read();
  113. do {
  114. ret = ret * 10 + c - '0';
  115. } while ((c = read()) >= '0' && c <= '9');
  116. if (neg)
  117. return -ret;
  118. return ret;
  119. }
  120.  
  121. public long nextLong() throws IOException {
  122. long ret = 0;
  123. byte c = read();
  124. while (c <= ' ')
  125. c = read();
  126. boolean neg = (c == '-');
  127. if (neg)
  128. c = read();
  129. do {
  130. ret = ret * 10 + c - '0';
  131. } while ((c = read()) >= '0' && c <= '9');
  132. if (neg)
  133. return -ret;
  134. return ret;
  135. }
  136.  
  137. public double nextDouble() throws IOException {
  138. double ret = 0, div = 1;
  139. byte c = read();
  140. while (c <= ' ')
  141. c = read();
  142. boolean neg = (c == '-');
  143. if (neg)
  144. c = read();
  145. do {
  146. ret = ret * 10 + c - '0';
  147. } while ((c = read()) >= '0' && c <= '9');
  148. if (c == '.')
  149. while ((c = read()) >= '0' && c <= '9')
  150. ret += (c - '0') / (div *= 10);
  151. if (neg)
  152. return -ret;
  153. return ret;
  154. }
  155.  
  156. private void fillBuffer() throws IOException {
  157. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  158. if (bytesRead == -1)
  159. buffer[0] = -1;
  160. }
  161.  
  162. private byte read() throws IOException {
  163. if (bufferPointer == bytesRead)
  164. fillBuffer();
  165. return buffer[bufferPointer++];
  166. }
  167.  
  168. public void close() throws IOException {
  169. if (din == null)
  170. return;
  171. din.close();
  172. }
  173. }
  174.  
  175. }
  176. //934600897 491649357 493374745 220431313 28399283
Success #stdin #stdout 0.07s 380160KB
stdin
2 
3 1 
1 2 3 
5 100 
1 11 111 1111 11111 
 
stdout
0 0 0 
1 1 1 1 1