#include #define N 100010 #define M 2000010 #define ll long long #define PII pair #define X first #define Y second #define MP make_pair #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; int n, k; int mi[N][20], a[N], mx[N][20]; void rmqInit(int a[]) { for(int i = 1; i <= n; i ++) mi[i][0] = mx[i][0] = a[i]; for(int j = 1; (1 << j) <= n; j ++) for(int i = 1; i + (1 << j) - 1 <= n; i ++) mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]), mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]); } int rmqMin(int mi[][20], int l, int r) { int k = (int)(log((double)(r - l + 1)) / log(2.0)); return min(mi[l][k], mi[r - (1 << k) + 1][k]); } int rmqMax(int mx[][20], int l, int r) { int k = (int)(log((double)(r - l + 1)) / log(2.0)); return max(mx[l][k], mx[r - (1 << k) + 1][k]); } struct node { int id, Or, And; }; int now, pre_or[N], pre_and[N]; vector dif[2]; multiset< int,greater > q; vector ins[N], era[N]; int main() { // freopen("in.txt", "r", stdin); scanf("%d%d", &n, &k); for(int i = 1; i<= n; i ++) { scanf("%d", &a[i]); pre_or[i] = (i != 1 ? (pre_or[i - 1] | a[i]) : a[i]); pre_and[i] = (i != 1 ? (pre_and[i - 1] & a[i]) : a[i]); } rmqInit(a); for(int i = 1; i <= n; i ++) { dif[now ^ 1].clear(); for(int j = 0; j < dif[now].size(); j ++) { if(!j) { int new_or = a[i] | dif[now][j].Or; int new_and = a[i] & dif[now][j].And; // if(i == 3) printf("%d %d %d %d\n", a[i], new_or, a[i], new_and); if(new_or != a[i] || new_and != a[i]) dif[now ^ 1].push_back((node){i, a[i], a[i]}); } else { int old_or = a[i] | dif[now][j - 1].Or; int old_and = a[i] & dif[now][j - 1].And; int new_or = a[i] | dif[now][j].Or; int new_and = a[i] & dif[now][j].And; if(new_or != old_or || new_and != old_and) dif[now ^ 1].push_back((node){dif[now][j-1].id, old_or, old_and}); } } dif[now ^ 1].push_back((node){1, pre_or[i], pre_and[i]}); now ^= 1; // printf("%d:\n", i); for(int j = 0; j < dif[now].size(); j ++) { int l = dif[now][j].id, r = (!j ? i : dif[now][j - 1].id-1), Or = dif[now][j].Or, And = dif[now][j].And; // printf("[%d %d] %d %d\n", l, r, Or, And); int tmp = Or - And - k; // if(i == 2) printf("%d tmp\n", tmp); //max-min<=k while(l < r) { int m = (l + r) >> 1; if(rmqMax(mx, m, i) - rmqMin(mi, m, i) <= tmp) r = m; else l = m + 1; } // if(i == 2) printf("%d %d %d ??\n", l, rmqMax(mx, l, i), rmqMin(mi, l, i)); if(rmqMax(mx, l, i) - rmqMin(mi, l, i) <= tmp) { // printf("ans : %d %d\n", l, i); ins[l].push_back(i - l + 1), era[i].push_back(i - l + 1); } } } for(int i = 1; i <= n; i ++) { for(int j = 0; j < ins[i].size(); j ++) { q.insert(ins[i][j]); } int x = *q.begin(); printf("%d\n", x ? x :-1); for(int j = 0; j < era[i].size(); j ++) { auto it = q.lower_bound(era[i][j]); q.erase(it); } } return 0; }