#include using namespace std; vector ans; vector maxTree; vector minTree; vector orTree; vector andTree; int n; void assign(int l, int r, int x) { l += n; r += n; for (; l < r; l >>= 1, r >>= 1) { if (l & 1) { ans[l] = max(ans[l], x); ++l; } if (r & 1) { --r; ans[r] = max(ans[r], x); } } } void build(const vector &a) { for (int i = n; i < 2 * n; ++i) { ans[i] = -1; maxTree[i] = minTree[i] = orTree[i] = andTree[i] = a[i - n]; } for (int i = n - 1; i >= 1; --i) { ans[i] = -1; maxTree[i] = max(maxTree[i << 1], maxTree[i << 1 | 1]); minTree[i] = min(minTree[i << 1], minTree[i << 1 | 1]); orTree[i] = orTree[i << 1] | orTree[i << 1 | 1]; andTree[i] = andTree[i << 1] & andTree[i << 1 | 1]; } } int cost(int l, int r) { int l0 = l; int r0 = r; int o = 0; // or int an = 1; // and // set all bits to 1 while (an < 1000000000) { an = an << 1 | 1; } int ma = 0; // max int mi = 2000000000; // min for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) { o |= orTree[l]; an &= andTree[l]; ma = max(ma, maxTree[l]); mi = min(mi, minTree[l]); ++l; } if (r & 1) { --r; o |= orTree[r]; an &= andTree[r]; ma = max(ma, maxTree[r]); mi = min(mi, minTree[r]); } } return (o - an) - (ma - mi); } void buildAnswersFinal() { for (int i = 1; i < n; ++i) { ans[i << 1] = max(ans[i << 1], ans[i]); ans[i << 1 | 1] = max(ans[i << 1 | 1], ans[i]); } } int main() { int k; cin >> n >> k; ans.resize(2 * n); maxTree.resize(2 * n); minTree.resize(2 * n); orTree.resize(2 * n); andTree.resize(2 * n); vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } build(a); for (int l = 0; l < n; ++l) { for (int r = l + 1; r <= n; ++r) { int c = cost(l, r); if (c >= k) { assign(l, r, r - l); } } } buildAnswersFinal(); for (int i = n; i < 2 * n; ++i) { cout << ans[i] << "\n"; } return 0; }