#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic #include #include //do setprecision #include #include using namespace std; #define FOR(i,b,e) for(int i=(b);i<(e);++i) #define FORQ(i,b,e) for(int i=(b);i<=(e);++i) #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i) #define REP(x, n) for(int x = 0; x < (n); ++x) #define ALL(u) (u).begin(),(u).end() #define ST first #define ND second #define PB push_back #define MP make_pair #define LL long long #define ULL unsigned LL #define LD long double typedef pair PII; const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342; const int MR = 5010; int mx[MR][MR], mn[MR][MR], a[MR][MR], o[MR][MR], cost[MR][MR]; int pref[MR]; bool done[MR]; vector costlyIntervals(int n, int k, vector A) { // Return a list of length n consisting of the answers REP(i, n) pref[i] = done[i] = 0; vector res(n, -1); REP(i, n) { o[i][i] = a[i][i] = mx[i][i] = mn[i][i] = A[i]; FOR(j, i + 1, n) { o[i][j] = (o[i][j - 1] | A[j]); a[i][j] = (a[i][j - 1] & A[j]); mx[i][j] = max(mx[i][j - 1], A[j]); mn[i][j] = min(mn[i][j - 1], A[j]); cost[i][j] = (o[i][j] - a[i][j]) - (mx[i][j] - mn[i][j]); } } FORD(sz, n + 1, 1) { REP(i, n - sz + 1) if (cost[i][i + sz - 1] >= k && pref[i + sz - 1] - (i ? pref[i - 1] : 0) < sz) { // cos mozemy poprawic FOR(j, i, i + sz) if (res[j] == -1) { res[j] = sz; done[j] = 1; pref[0] = done[0]; FOR(l, 1, n) pref[l] = pref[l - 1] + done[l]; } } } 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; }