#include #include #include #include using namespace std; const int BACKET = 130; int N, K, Q, A[15009], X[15009], V[15009], ans[15009]; bool used[15009]; bitset<15009>ZERO; void query(int cl, int cr) { for (int i = 1; i <= N; i++) used[i] = false; vector J; for (int i = cl; i <= cr; i++) { used[X[i]] = true; J.push_back(X[i]); } sort(J.begin(), J.end()); J.erase(unique(J.begin(), J.end()), J.end()); bitset<15009> G = ZERO; G.set(0); for (int i = 1; i <= N; i++) { if (used[i] == false) G |= (G << A[i]); } for (int i = cl; i <= cr; i++) { A[X[i]] = V[i]; bitset<15009>H = G; for (int pos : J) H |= (H << A[pos]); if (H[K] == 1) ans[i] = 1; else ans[i] = 0; } } int main() { cin >> N >> K; for (int i = 1; i <= N; i++) cin >> A[i]; cin >> Q; for (int i = 1; i <= Q; i++) cin >> X[i] >> V[i]; for (int i = 1; i <= Q; i += BACKET) { int cl = i, cr = min(Q, i + BACKET - 1); query(cl, cr); } for (int i = 1; i <= Q; i++) cout << ans[i] << endl; return 0; }