#include #define rep(i,a,b) for(int i=a;i=b;i--) #define fore(i,a) for(auto &i:a) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- #define def 0 template struct SegTree { //[l,r) V comp(V& l, V& r) { return max(l,r); }; vector val; SegTree() { val = vector(NV * 2, def); } V get(int x,int y,int l=0,int r=NV,int k=1){if(r<=x||y<=l)return def;if(x<=l&&r<=y)return val[k]; auto a=get(x,y,l,(l+r)/2,k*2);auto b=get(x,y,(l+r)/2,r,k*2+1);return comp(a,b);} void update(int i, V v) { i+=NV;val[i]=v;while(i>1)i>>=1,val[i]=comp(val[i*2],val[i*2+1]); } void add(int i, V v) { update(i, val[i + NV] + v); } V operator[](int x) { return get(x, x + 1); }}; #define INF INT_MAX/2 #define def2 make_tuple(0, INF, 0, -1) template struct SegTree2 { //[l,r) V comp(V& l, V& r) { int a, b, c, d, e, f, g, h; tie(a, b, c, d) = l; tie(e, f, g, h) = r; return make_tuple(max(a, e), min(b, f), c | g, d & h); }; vector val; SegTree2() { val = vector(NV * 2, def2); } V get(int x,int y,int l=0,int r=NV,int k=1){if(r<=x||y<=l)return def2;if(x<=l&&r<=y)return val[k]; auto a=get(x,y,l,(l+r)/2,k*2);auto b=get(x,y,(l+r)/2,r,k*2+1);return comp(a,b);} void update(int i, V v) { i+=NV;val[i]=v;while(i>1)i>>=1,val[i]=comp(val[i*2],val[i*2+1]); } void add(int i, V v) { update(i, val[i + NV] + v); } V operator[](int x) { return get(x, x + 1); }}; int N, A[101010], K; SegTree st; SegTree2, 1 << 17> st2; int get(int L, int R) { int vma, vmi, vor, van; tie(vma, vmi, vor, van) = st2.get(L, R); return (vor - van) - (vma - vmi); } //----------------------------------------------------------------------------------- int nxtup[101010][32], nxtdwn[101010][32], memo[32]; void pre() { rep(i, 0, 32) memo[i] = N; rrep(i, N - 1, 0) { rep(j, 0, 32) nxtup[i][j] = memo[j]; rep(j, 0, 32) if (A[i] & (1 << j)) memo[j] = i; } rep(i, 0, 32) memo[i] = N; rrep(i, N - 1, 0) { rep(j, 0, 32) nxtdwn[i][j] = memo[j]; rep(j, 0, 32) if (!(A[i] & (1 << j))) memo[j] = i; } } int gonext(int L, int R) { if (R == N) return N; int vma, vmi, vor, van; tie(vma, vmi, vor, van) = st2.get(L, R); int res = N; rep(i, 0, 32) if (!(vor & (1 << i))) res = min(res, nxtup[R][i]); rep(i, 0, 32) if (van & (1 << i)) res = min(res, nxtdwn[R][i]); return res; } //----------------------------------------------------------------------------------- void _main() { cin >> N >> K; rep(i, 0, N) cin >> A[i]; rep(i, 0, N) st2.update(i, make_tuple(A[i], A[i], A[i], A[i])); pre(); rep(L, 0, N) { if (K <= get(L, L + 1)) st.update(L, 1); int R = L; while (R < N) { int RR = gonext(L, R); if (get(L, R + 1) < K) { R = RR; continue; } int ok = R, ng = RR; while (ok + 1 != ng) { int x = (ok + ng) / 2; if (K <= get(L, x + 1)) ok = x; else ng = x; } int a = st.get(ok, ok + 1); st.update(ok, max(a, ok - L + 1)); R = RR; } int ans = st.get(L, N); if (ans == 0) ans = -1; printf("%d\n", ans); } }