#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template void chmin(T &t, const T &f) { if (t > f) t = f; } template void chmax(T &t, const T &f) { if (t < f) t = f; } int N, K; int A[20010]; int Q; int X[20010], V[20010]; int a[20010]; constexpr int H = 4; int MOs[10]; int dp[10][20010]; void init() { for (int h = 0; h < H; ++h) { fill(dp[h], dp[h] + K + 1, 0); dp[h][0] = 1; } } void add(int x) { if (x != 0) { for (int h = 0; h < H; ++h) { for (int j = K; j >= x; --j) { if ((dp[h][j] += dp[h][j - x]) >= MOs[h]) { dp[h][j] -= MOs[h]; } } } } } void remove(int x) { if (x != 0) { for (int h = 0; h < H; ++h) { for (int j = x; j <= K; ++j) { if ((dp[h][j] -= dp[h][j - x]) < 0) { dp[h][j] += MOs[h]; } } } } } int get() { for (int h = 0; h < H; ++h) { if (dp[h][K] != 0) { return 1; } } return 0; } int main() { MOs[0] = 998244353; MOs[1] = 1000000007; random_device device; mt19937 rng(device()); uniform_int_distribution distr(505005005, 1001001001); for (int h = 2; h < H; ++h) { MOs[h] = distr(rng); } // cerr<<"MOs = ";pv(MOs,MOs+H); for (; ~scanf("%d%d", &N, &K); ) { for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); } scanf("%d", &Q); for (int q = 0; q < Q; ++q) { scanf("%d%d", &X[q], &V[q]); --X[q]; } init(); for (int i = 0; i < N; ++i) { add(A[i]); } copy(A, A + N, a); for (int q = 0; q < Q; ++q) { remove(a[X[q]]); a[X[q]] = V[q]; add(a[X[q]]); // pv(a,a+N); // pv(dp[0],dp[0]+K+1); // pv(dp[1],dp[1]+K+1); printf("%d\n", get()); } } return 0; }