import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.InputMismatchException; import java.util.TreeSet; public class D2 { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), K = ni(); int[] a = na(n); int[] ra = new int[n]; for(int i = 0;i < n;i++)ra[i] = -a[i]; int[][] stmin = build(a); int[][] stmax = build(ra); int[][] efs = new int[80*n][]; int efp = 0; int esp = 0; int[][] oas = new int[0][]; for(int i = n-1;i >= 0;i--){ int[][] noas = new int[40][]; int p = 0; for(int j = 0;j < oas.length;j++){ oas[j][0] |= a[i]; oas[j][1] &= a[i]; if(p > 0 && noas[p-1][0] == oas[j][0] && noas[p-1][1] == oas[j][1]){ noas[p-1][2] = oas[j][2]; }else{ noas[p++] = oas[j]; } } if(!(p > 0 && noas[p-1][0] == a[i] && noas[p-1][1] == a[i])){ noas[p++] = new int[]{a[i], a[i], i}; }else{ noas[p-1][2] = i; } oas = Arrays.copyOf(noas, p); // tr(i, oas); int to = n; for(int[] oa : oas){ // [oa[2], to) int cha = oa[0] - oa[1]; int low = oa[2]-1, high = to; while(high - low > 1){ int h = high+low>>1; // [i,h] // tr(h, oa, to, cha, -rmq(stmax, i, h+1) - rmq(stmin, i, h+1)); if(cha - (-rmq(stmax, i, h+1) - rmq(stmin, i, h+1)) >= K){ low = h; }else{ high = h; } } if(low >= oa[2]){ // tr(i, oa, to, low); efs[efp++] = new int[]{i, low - i + 1, i}; efs[efp++] = new int[]{low+1, low - i + 1, i}; } to = oa[2]; } } int I = -1; int[] anss = new int[n]; Arrays.fill(anss, I); Arrays.sort(efs, 0, efp, new Comparator() { public int compare(int[] a, int[] b) { return a[0] - b[0]; } }); TreeSet set = new TreeSet(); int q = 0; for(int i = 0;i < n;i++){ while(q < efp && efs[q][0] <= i){ long code = (long)efs[q][1]<<32|efs[q][2]; if(set.contains(code)){ set.remove(code); }else{ set.add(code); } q++; } if(!set.isEmpty()){ Long first = set.last(); anss[i] = Math.max(anss[i], (int)(first>>>32)); } } for(int v : anss){ out.println(v); } } public static int[][] build(int[] a) { int n = a.length; int b = 32-Integer.numberOfLeadingZeros(n); int[][] ret = new int[b][]; for(int i = 0, l = 1;i < b;i++, l*=2) { if(i == 0) { ret[i] = a; }else { ret[i] = new int[n-l+1]; for(int j = 0;j < n-l+1;j++) { ret[i][j] = Math.min(ret[i-1][j], ret[i-1][j+l/2]); } } } return ret; } // [a,b) public static int rmq(int[][] or, int l, int r) { assert l <= r; if(l >= r)return Integer.MAX_VALUE; // 1:0, 2:1, 3:1, 4:2, 5:2, 6:2, 7:2, 8:3 int t = 31-Integer.numberOfLeadingZeros(r-l); return Math.min(or[t][l], or[t][r-(1<= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char)skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }