#include using namespace std; #define mid (lf + rg >> 1) #define right (left | 1) #define left (v << 1) #define pb push_back #define mp make_pair #define nd second #define st first typedef long long ll; typedef pair < int, int > pii; const ll linf = 2e18 + 9; const int inf = 1e9 + 9; const int mod = 1e9 + 7; const int N = 2e6 + 9; const int kokn = 350; const int logN = 30; ll n, m, k, a[N], tree[N * 4], lazy[N * 4], dp[N], used[N], used2[N], fen[N]; vector < int > gr[N]; stack < int > Q, Q2; ll temp; void update2(int v, int lf, int rg, int pos, int val) { if (lf == rg) { tree[v] = max(tree[v], (ll) val); return ; } if (pos <= mid) update2(left, lf, mid, pos, val); else update2(right, mid + 1, rg, pos, val); tree[v] = max(tree[left], tree[right]); } ll query2(int v, int lf, int rg, int l, int r) { if (l > rg or r < lf) return 0; if (l <= lf and rg <= r) return tree[v]; return max(query2(left, lf, mid, l, r), query2(right, mid + 1, rg, l, r)); } void push(int v, int lf, int rg) { if (lazy[v] != 0) { tree[v] += lazy[v]; if (lf != rg) { lazy[left] += lazy[v]; lazy[right] += lazy[v]; } lazy[v] = 0; } } void update(int v, int lf, int rg, int l, int r, ll val) { push(v, lf, rg); if (l > rg or r < lf) return ; if (l <= lf and rg <= r) { tree[v] += val; if (lf != rg) { lazy[left] += val; lazy[right] += val; } return ; } update(left, lf, mid, l, r, val); update(right, mid + 1, rg, l, r, val); tree[v] = max(tree[left], tree[right]); } ll query(int v, int lf, int rg, int l, int r) { push(v, lf, rg); if (l > rg or r < lf or tree[v] < k) return -1LL; if (lf == rg) return rg; if ((temp = query(left, lf, mid, l, r)) != -1) return temp; return query(right, mid + 1, rg, l, r); } int main() { Q.push(0); Q2.push(0); scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { ll front = i - 1; ll cur = 0; while (Q2.size() != 0) { ll _mn = Q2.top(); update(1, 1, n, _mn + 1, front, a[i] - cur); if (a[_mn] <= a[i] or _mn == 0) break; front = _mn; cur = a[_mn]; Q2.pop(); } front = i - 1; cur = 0; while (Q.size() != 0) { ll _mx = Q.top(); update(1, 1, n, _mx + 1, front, cur - a[i]); if (a[_mx] >= a[i] or _mx == 0) break; front = _mx; cur = a[_mx]; Q.pop(); } for (int j = logN - 1; j >= 0; j--) { if ((a[i] >> j & 1) == 0 and used[j]) { update(1, 1, n, used[j], i - 1, (1 << j)); used[j] = false; } else if (a[i] >> j & 1) { update(1, 1, n, used2[j] + 1, i - 1, (1 << j)); if (!used[j]) used[j] = i; used2[j] = i; } } Q.push(i); Q2.push(i); ll temp = query(1, 1, n, 1, i); if (temp != -1) gr[temp].pb(i); } memset(tree, 0, sizeof tree); for (int i = 1; i <= n; i++) { for (int j = 0; j < gr[i].size(); j++) { ll t = gr[i][j]; update2(1, 1, n, t, t - i + 1); } dp[i] = query2(1, 1, n, i, n); if (!dp[i]) printf("-1 "); else printf("%lld\n", dp[i]); } return 0; }