#include #define MAXN 100010 using namespace std; int ans[MAXN]; void costlyIntervals(int n, int k, vector A) { // Return a list of length n consisting of the answers int ma, mi; int Or; int And; for(int i = 0; i < n; i++){ ma = mi = Or = And = A[i]; int t = -1, l = -1; for(int j = i; j < n; j++){ ma = max(ma, A[j]); mi = min(mi, A[j]); And &= A[j]; Or |= A[j]; if((Or - And) - (ma - mi) >= k) t = j - i + 1, l = j; } for(int j = l; j >= i; j--){ ans[j] = max(ans[j], t); } } } int main() { int n; int k; cin >> n >> k; vector A(n); for(int A_i = 0; A_i < n; A_i++){ cin >> A[A_i]; } memset(ans, -1, sizeof(ans)); costlyIntervals(n, k, A); for (ssize_t i = 0; i < n; i++) { cout << ans[i] << (i != n - 1 ? "\n" : ""); } cout << endl; return 0; }