#include #define SIZE 100010 using namespace std; int nxt[SIZE] = {0}; void costlyIntervals(int n, int k, vector A) { // Return a list of length n consisting of the answers for (int i = 0 ; i < n ; ++i) { int And = (1 << 30) - 1, Or = 0, Mx = 0, Mn = 1e9 + 7, idx = -1; for (int j = i ; j < n ; ++j) { And &= A[j]; Or |= A[j]; Mx = max(Mx, A[j]); Mn = min(Mn, A[j]); if (Or - Mx + Mn - And >= k) idx = j; } if (idx != -1) nxt[i] = idx; else nxt[i] = i - 2; } for (int i = 0 ; i < n ; ++i) { int ans = -1; for (int j = 0 ; j <= i ; ++j) { if (nxt[j] >= i) ans = max(ans, nxt[j] - j + 1); } printf("%d\n", ans); } } int main() { int n; int k; scanf("%d %d", &n, &k); vector A(n); for(int A_i = 0; A_i < n; A_i++){ scanf("%d", &A[A_i]); } costlyIntervals(n, k, A); return 0; }