#include #include #include #include #include #include #include #include #include #include #include using namespace std; // Common Utilities //____________________________________________________________ // Constants constexpr bool DEBUG = true; constexpr float EPSILON = 1E-10; constexpr long long MOD = 1000000007; constexpr int MAX_INT = 2147483647; constexpr long long MAX_LONG = 9223372036854775807; // Functions template ostream& operator<<(ostream& out, const vector& v) { if (v.size() == 0) { return out << "[]"; } out << '[' << v[0]; for (int i = 1; i < v.size(); ++i) { out << ' ' << v[i]; } return out << ']'; } // Solution //____________________________________________________________ // Classes struct Element { int size; int expiry; bool operator<(const Element& e) const { return (size < e.size) || (size == e.size && expiry > e.expiry); } }; // Declarations // Functions int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } vector answers(N, -1); for (int i = 0; i < N; ++i) { unsigned int _or = 0; unsigned int _and = -1; unsigned int _min = -1; unsigned int _max = 0; int size = -1; for (int j = i; j < N; ++j) { _or |= A[j]; _and &= A[j]; _min = min(_min, A[j]); _max = max(_max, A[j]); int cost = (_or - _and) - (_max - _min); if (cost >= K) { size = j - i + 1; answers[i] = size; } //cerr << _or << " " << _and << " " << _min << " " << _max << '\n'; //cerr << "A[" << i << "..." << j << "]: " << cost << '\n'; } } priority_queue> q; for (int i = 0; i < N; ++i) { while (!q.empty() && q.top().expiry < i) { q.pop(); } if (q.empty()) { cout << answers[i] << '\n'; } else { cout << max(answers[i], q.top().size) << '\n'; } if (answers[i] > -1) { q.push(Element{answers[i], i + answers[i] - 1}); } } return 0; }