/** author: shobonvip created: 2024.12.10 05:13:57 **/ #include using namespace std; //* ATCODER #include using namespace atcoder; typedef dynamic_modint<1> mint1; typedef dynamic_modint<2> mint2; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) #define all(v) v.begin(), v.end() template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } // isprime bool is_prime(ll n){ if (n == 1) return false; for (ll i = 2; i * i <= n; i++){ if (n % i == 0) return false; } return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist(9e8,1e9); int mod1, mod2; do { mod1 = dist(engine); }while(!is_prime(mod1)); do { mod2 = dist(engine); }while(!is_prime(mod2) || mod1 == mod2); mint1::set_mod(mod1); mint2::set_mod(mod2); int n, k; cin >> n >> k; vector a(n); rep(i,0,n) cin >> a[i]; vector f1(k+1); vector f2(k+1); f1[0] = 1; f2[0] = 1; rep(i,0,n) { if (a[i] == 0) continue; vector nf1(k+1); vector nf2(k+1); rep(j,0,k+1) { nf1[j] += f1[j]; nf2[j] += f2[j]; if (j+a[i] <= k) { nf1[j+a[i]] += f1[j]; nf2[j+a[i]] += f2[j]; } } swap(nf1, f1); swap(nf2, f2); } int q; cin >> q; while(q--) { int x, v; cin >> x >> v; x--; if (a[x] != 0) { rep(j,0,k+1) { if (j-a[x] >= 0) { f1[j] -= f1[j-a[x]]; f2[j] -= f2[j-a[x]]; } } } a[x] = v; if (a[x] != 0) { vector nf1(k+1); vector nf2(k+1); rep(j,0,k+1) { nf1[j] += f1[j]; nf2[j] += f2[j]; if (j+a[x] <= k) { nf1[j+a[x]] += f1[j]; nf2[j+a[x]] += f2[j]; } } swap(nf1, f1); swap(nf2, f2); } if (f1[k].val() != 0 && f2[k].val() != 0) { cout << 1 << '\n'; }else { cout << 0 << '\n'; } } }