Bitmasking and searching consecutive 1's
&lt;bits/stdc++.h&gt; (like everything in your compiler's bits/ subtree) is not a standard header and therefore not portable.  Even if you're willing to sacrifice portability, it's a poor choice, as it will slow compilation down compared to simply including what you use.

using namespace std; is poor practice.  It makes your code less clear, and it may even silently change its meaning.

Don't use the preprocessor to name constants.  Use a properly scoped, strongly typed C++ constant:

constexpr std::size_t max = 100000;


When using input streams, always check that operations succeed before using their results.

Variable names should be more descriptive.  I have no idea what n, q, and k are supposed to be storing.  In fact, these names are so useless that I gave up reading at this point - it's not at all clear what this is supposed to be doing.