#include using namespace std; vector costlyIntervals(int n, int k, vector &A) { // Return a list of length n consisting of the answers vector rtn(n, -1); vector > OR(n, vector(n, 0)); // or[l][r] stores A[l] | A[l + 1] | ... | A[r] vector > AND(n, vector(n, 0)); // and[l][r] stores A[l] & ... & A[r] vector > MIN(n, vector(n, 0)); // min[l][r] stores min(A[l], ..., A[r]) vector > MAX(n, vector(n, 0)); // max[l][r] stores max(A[l], ..., A[r]) vector > COST(n, vector(n, 0)); // cost[l][r] stores cost of A[l], ..., A[r] vector rightmost(n, -1); // rightmost[i] stores the index j, s.t. cost[i][j] >= k for (int l = 0; l < n; l++) { OR[l][l] = A[l]; AND[l][l] = A[l]; MIN[l][l] = A[l]; MAX[l][l] = A[l]; COST[l][l] = 0; for (int r = l + 1; r < n; r++) { OR[l][r] = OR[l][r - 1] | A[r]; AND[l][r] = AND[l][r - 1] & A[r]; MIN[l][r] = min(MIN[l][r - 1], A[r]); MAX[l][r] = max(MAX[l][r - 1], A[r]); COST[l][r] = (OR[l][r] - AND[l][r]) - (MAX[l][r] - MIN[l][r]); if (COST[l][r] >= k) rightmost[l] = r; } } for (int l = 0; l < n; l++) { for (int i = l; i <= rightmost[l]; i++) { rtn[i] = max(rtn[i], rightmost[l] - l + 1); } } return rtn; } 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; }