#include using namespace std; struct node { int left; int right; int cost; }; bool comp(const node &a, const node &b) { return (a.right+1-a.left) > (b.right+1-b.left); } vector costlyIntervals(int n, int k, vector a) { vector v; vector res; map> m; for (int i = 0; i < n; i++) { if (m.find(a[i]) != m.end()) { m[a[i]].push_back(i); } else { vector x; x.push_back(i); m[a[i]] = x; } int min = a[i], max = a[i], ora = a[i], anda = a[i]; for (int j = i+1; j < n; j++) { if (min > a[j]) min = a[j]; if (max < a[j]) max = a[j]; ora |= a[j]; anda &= a[j]; node s; s.left = i; s.right = j; s.cost = (ora-anda)-(max-min); if (s.cost >= k) v.push_back(s); } } sort(v.begin(), v.end(), comp); int i; for (int index = 0; index < a.size(); index++) { bool find = false; for ( i = 0; i < v.size(); i++) { if (find) break; vector y =m[a[index]]; for (int j = 0; j < y.size(); j++) { if (y[j]>=v[i].left && y[j]<=v[i].right) { res.push_back(v[i].right+1-v[i].left); find = true; break; } } } if (!find && i == v.size()) res.push_back(-1); } return res; } 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]; } vector result = costlyIntervals(n, k, A); for (ssize_t i = 0; i < result.size(); i++) { cout << result[i] << (i != result.size() - 1 ? "\n" : ""); } cout << endl; return 0; }