You are given an array $a$ consisting of $n$ integers. Initially all elements of $a$ are either $0$ or $1$. You need to process $q$ queries of two kinds:

1 x : Assign to $a_x$ the value $1 - a_x$.

2 k : Print the $k$-th largest value of the array.

As a reminder, $k$-th largest value of the array $b$ is defined as following:

Sort the array in the non-increasing order, return $k$-th element from it.

For example, the second largest element in array $[0, 1, 0, 1]$ is $1$, as after sorting in non-increasing order it becomes $[1, 1, 0, 0]$, and the second element in this array is equal to $1$.


-----Input-----

The first line contains two integers $n$ and $q$ ($1 \le n, q \le 10^5$) — the length of the given array and the number of queries.

The second line contains $n$ integers $a_1, a_2, a_3, \dots, a_n$ ($0 \le a_i \le 1$) — elements of the initial array.

Each of the following $q$ lines contains two integers. The first integer is $t$ ($1 \le t \le 2$) — the type of query.

If $t = 1$ the second integer is $x$ ($1 \le x \le n$) — the position of the modified number. You have to assign to $a_x$ the value $1 - a_x$.

If $t = 2$ the second integer is $k$ ($1 \le k \le n$) — you need to print the $k$-th largest value of the array.

It's guaranteed that there will be at least one query of the second type (satisfying $t = 2$).


-----Output-----

For each query of the second type, print a single integer — the answer to the query.


-----Examples-----

Input
5 5
1 1 0 1 0
2 3
1 2
2 3
2 1
2 5
Output
1
0
1
0


-----Note-----

Initially $a = [1, 1, 0, 1, 0]$.

The first operation is printing the third largest value, which is $1$.

The second operation is assigning $a_2$ the value $0$, $a$ becomes $[1, 0, 0, 1, 0]$.

The third operation is printing the third largest value, it is $0$.

The fourth operation is printing the first largest value, it is $1$.

The last operation is printing the fifth largest value, it is $0$.

Source: codeforces | Difficulty: EASY
Tags: Complete search

Implementation

Greedy algorithms


Solutions:
(cs, ln) = map(int, input().split())
ar = list(map(int, input().split()))
z = ar.count(0)
(o, sol) = (cs - z, [])
while ln:
	ln -= 1
	(qst, pl) = map(int, input().split())
	if qst == 2:
		if cs - pl >= z:
			sol.append(1)
		else:
			sol.append(0)
	elif ar[pl - 1] == 0:
		ar[pl - 1] = 1
		o += 1
		z -= 1
	else:
		ar[pl - 1] = 0
		o -= 1
		z += 1
print(*sol, sep='\n')


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
ones = arr.count(1)
zeros = n - ones
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		if arr[b - 1] == 1:
			zeros += 1
			ones -= 1
			arr[b - 1] ^= 1
		else:
			ones += 1
			zeros -= 1
			arr[b - 1] ^= 1
	elif b > ones:
		print(0)
	else:
		print(1)


one = 0

def assign(m):
	global one
	if a[m - 1] == 1:
		a[m - 1] = 0
		one = one - 1
	else:
		a[m - 1] = 1
		one = one + 1

def show(n):
	if n <= one:
		print('1')
	else:
		print('0')
(n, q) = [int(g) for g in input().split()]
a = [int(h) for h in input().split()]
for item in a:
	if item == 1:
		one += 1
for i in range(q):
	(t, x) = [int(j) for j in input().split()]
	if t == 1:
		assign(x)
	if t == 2:
		show(x)


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
n0 = arr.count(0)
n1 = n - n0
for _ in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if arr[x - 1] == 1:
			n0 += 1
			n1 -= 1
			arr[x - 1] = 0
		else:
			n0 -= 1
			n1 += 1
			arr[x - 1] = 1
	elif x <= n1:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline

def read_number():
	return int(input())

def read_list():
	return list(map(int, input().split()))

def read_string():
	s = input()
	return list(s[:len(s) - 1])

def read_separated_numbers():
	return map(int, input().split())
first_row = read_list()
(n, q) = (first_row[0], first_row[1])
values = read_list()
flag = False
total = sum(values)
for i in range(q):
	input_line = read_list()
	t = input_line[0]
	if t == 1:
		x = input_line[1]
		values[x - 1] = 1 - values[x - 1]
		if values[x - 1] == 1:
			total += 1
		else:
			total -= 1
	else:
		k = input_line[1]
		if k <= total:
			print(str(1))
		else:
			print(str(0))


from math import *
from sys import *
from bisect import *
from collections import *
(n, q) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
s = sum(a)
for i in range(q):
	(t, x) = map(int, stdin.readline().split())
	if t == 1:
		if a[x - 1] == 1:
			s -= 1
			a[x - 1] = 0
		else:
			s += 1
			a[x - 1] = 1
	elif x <= s:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
x = 0
for i in a:
	if i == 1:
		x += 1
for i in range(q):
	(c, d) = map(int, input().split())
	if c == 2:
		if d > x:
			print(0)
		else:
			print(1)
	else:
		d -= 1
		if a[d] == 0:
			a[d] = 1
			x += 1
		else:
			a[d] = 0
			x -= 1


from copy import deepcopy as d
(n, t) = map(int, input().split())
a = [int(i) for i in input().split()]
j = d(a)
j.sort(reverse=True)
e = j.index(0)
res = []
for i in range(t):
	(r, s) = map(int, input().split())
	if r == 1:
		if 1 - a[s - 1] == 0:
			j[e - 1] = 0
			e -= 1
			a[s - 1] = 1 - a[s - 1]
		else:
			j[e] = 1
			e += 1
			a[s - 1] = 1 - a[s - 1]
	else:
		res.append(j[s - 1])
for i in res:
	print(i)


import sys

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
(n, q) = inpl()
a = inpl()
sorted_a = sorted(a, reverse=True)
if 0 not in sorted_a:
	first_zero = n + 1
else:
	first_zero = sorted_a.index(0) + 1
for _ in range(q):
	(t, k) = inpl()
	if t == 1:
		a[k - 1] = 1 - a[k - 1]
		if a[k - 1] == 1:
			first_zero += 1
		else:
			first_zero -= 1
	elif k >= first_zero:
		print(0)
	else:
		print(1)


def ass(a, b):
	if a != b:
		print(f'Assertion error:\n{a}\n{b}')

def intline():
	return [int(item) for item in input().split()]

def line():
	return [item for item in input().split()]

def dump(lst):
	for (i, item) in enumerate(lst):
		print(i, item)

def binsearch(arr, a, b):
	m = (a + b) // 2
	if a >= b:
		return a - 1 if arr[a] == 0 else a
	return binsearch(arr, a, m - 1) if arr[m] == 0 else binsearch(arr, m + 1, b)

def f(values, queries):
	total = sum(values)
	result = []
	for (t, x) in queries:
		if t == 1:
			total += -1 if values[x - 1] == 1 else 1
			values[x - 1] = 1 - values[x - 1]
		if t == 2:
			result.append(1 if x <= total else 0)
	return result
(n, q) = intline()
values = intline()
queries = [intline() for i in range(q)]
for res in f(values, queries):
	print(res)


(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
t1 = []
t2 = []
for i in range(q):
	(tmp1, tmp2) = list(map(int, input().split()))
	t1.append(tmp1)
	t2.append(tmp2)
add = sum(a)
for (i, j) in zip(t1, t2):
	if i == 1:
		a[j - 1] = 1 - a[j - 1]
		if a[j - 1] == 1:
			add = add + 1
		else:
			add = add - 1
	elif j <= add:
		print(1)
	else:
		print(0)


(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
one = 0
zero = 0
for x in a:
	if x == 1:
		one += 1
	else:
		zero += 1
for _ in range(q):
	(x, y) = list(map(int, input().split()))
	if x == 1:
		if a[y - 1] == 1:
			a[y - 1] = 0
			one -= 1
			zero += 1
		else:
			a[y - 1] = 1
			one += 1
			zero -= 1
	if x == 2:
		if y <= one:
			print(1)
		else:
			print(0)


import math
from collections import defaultdict
from math import comb
from sys import stdout
NO = 'NO'
YES = 'YES'
MOD = 1000000007

def input_int():
	return int(input())

def input_list():
	return input().split(' ')

def input_list_int():
	return list(map(int, input_list()))

def z_func(s):
	n = len(s)
	z = [0] * n
	l = r = 0
	for i in range(1, n):
		if r >= i:
			z[i] = min(z[i - l], r - i + 1)
		while z[i] + i < n and s[z[i]] == s[z[i] + i]:
			z[i] += 1
		if i + z[i] - 1 > r:
			l = i
			r = i + z[i] - 1
	return z
global_ans = []

def p(a):
	global_ans.append(a)

def solve():
	(n, q) = input_list_int()
	a = input_list_int()
	tmp = 0
	for i in a:
		if i == 1:
			tmp += 1
	for i in range(q):
		(t, x) = input_list_int()
		if t == 1:
			tmp += -1 if a[x - 1] == 1 else 1
			a[x - 1] = 1 - a[x - 1]
		else:
			p(1 if x <= tmp else 0)
query_count = 1
while query_count:
	query_count -= 1
	solve()
for global_ans_line in global_ans:
	print(global_ans_line)


(n, q) = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
s = sum(l)
for _ in range(q):
	(command, index) = list(map(int, input().strip().split()))
	if command == 1:
		l[index - 1] = 1 - l[index - 1]
		if l[index - 1] == 0:
			s -= 1
		else:
			s += 1
	elif command == 2:
		print(int(index <= s))


import sys
from collections import Counter
(n, q) = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
c = Counter(A)
for _ in range(q):
	(t, k) = map(int, sys.stdin.readline().split())
	if t == 2:
		print(1 if c[1] >= k else 0)
	else:
		old = A[k - 1]
		new = 1 - old
		A[k - 1] = new
		c[old] -= 1
		c[new] += 1


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
(N, Q) = map(int, wtf[0].split())
A = list(map(int, wtf[1].split()))
O = A.count(1)
Z = A.count(0)
for q in wtf[2:]:
	(t, x) = map(int, q.split())
	if t == 1:
		A[x - 1] = 1 - A[x - 1]
		if A[x - 1] == 1:
			O += 1
			Z -= 1
		else:
			O -= 1
			Z += 1
	else:
		print(1 if x <= O and O > 0 else 0)


from collections import deque
import sys

def main():
	input()
	valores = input().split()
	ordenado = deque(sorted(valores, reverse=True))
	for e in sys.stdin:
		(t, k) = e.split()
		k = int(k)
		if t == '1':
			if valores[k - 1] == '1':
				ordenado.popleft()
				ordenado.append('0')
				valores[k - 1] = '0'
			else:
				ordenado.pop()
				ordenado.appendleft('1')
				valores[k - 1] = '1'
		else:
			print(ordenado[k - 1])
main()


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, Q, A, queries):
	assert len(A) == N
	assert len(queries) == Q
	freq = Counter(A)
	ans = []
	for (kind, x) in queries:
		if kind == 1:
			x -= 1
			old = A[x]
			A[x] ^= 1
			freq[old] -= 1
			freq[old ^ 1] += 1
		else:
			assert kind == 2
			if x <= freq[1]:
				ans.append('1')
			else:
				ans.append('0')
	return '\n'.join(ans)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = 1
for tc in range(1, TC + 1):
	(N, Q) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	queries = [[int(x) for x in input().split()] for i in range(Q)]
	ans = solve(N, Q, A, queries)
	print(ans)


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
count = sum(arr)
answer = []
for _ in range(q):
	(t, kx) = map(int, input().split())
	if t == 1:
		arr[kx - 1] = 1 - arr[kx - 1]
		if arr[kx - 1]:
			count += 1
		else:
			count -= 1
	elif count >= kx:
		answer.append(1)
	else:
		answer.append(0)
for i in answer:
	print(i)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
for _ in range(1):
	(n, q) = LI()
	a = LI()
	cnt = a.count(1)
	for el in range(q):
		(t, x) = LI()
		if t == 1:
			if a[x - 1] == 1:
				a[x - 1] = 0
				cnt -= 1
			else:
				a[x - 1] = 1
				cnt += 1
		elif x > cnt:
			print(0)
		else:
			print(1)


import sys
inputlines = sys.stdin.readlines()
(n, q) = list(map(int, inputlines[0].split(' ')))
elements = list(map(int, inputlines[1].split(' ')))
number_of_zeroes = 0
number_of_ones = 0
for i in elements:
	if i == 0:
		number_of_zeroes += 1
	else:
		number_of_ones += 1
for i in range(q):
	(t, x) = list(map(int, inputlines[i + 2].split(' ')))
	if t == 2:
		if number_of_ones >= x:
			print(1)
		else:
			print(0)
	else:
		if elements[x - 1] == 0:
			number_of_ones += 1
			number_of_zeroes -= 1
		else:
			number_of_ones -= 1
			number_of_zeroes += 1
		elements[x - 1] = 1 - elements[x - 1]


import sys
from collections import Counter
input = sys.stdin.readline

def main():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter(a)
	for _ in range(q):
		(t, x) = map(int, input().split())
		if t == 1:
			if a[x - 1] == 0:
				c[0] -= 1
				c[1] += 1
			else:
				c[0] += 1
				c[1] -= 1
			a[x - 1] = 1 - a[x - 1]
		elif x > c[1]:
			print(0)
		else:
			print(1)
main()


from collections import Counter

def read_input(filename: str=None):
	from sys import stdin
	stdin = open(filename) if filename else stdin
	(_, cases) = tuple(map(int, stdin.readline().split()))
	values = list(map(int, stdin.readline().split()))
	counter = Counter(values)
	while cases:
		cases = cases - 1
		(operation, index) = tuple(map(int, stdin.readline().split()))
		if not operation - 1:
			index = index - 1
			values[index] = values[index] ^ 1
			counter[values[index]] = counter[values[index]] + 1
			counter[values[index] ^ 1] = counter[values[index] ^ 1] - 1
			continue
		if index <= counter[1]:
			print('1')
			continue
		print('0')

def main():
	read_input()
main()


(n, q) = map(int, input().split())
s = input().split()
res = []
Os = 0
Zs = 0
for i in range(0, n):
	if s[i] == '0':
		Zs += 1
	else:
		Os += 1
for i in range(0, q):
	qr = input().split()
	if qr[0] == '1':
		if s[int(qr[1]) - 1] == '1':
			s[int(qr[1]) - 1] = '0'
			Os -= 1
			Zs += 1
		else:
			s[int(qr[1]) - 1] = '1'
			Os += 1
			Zs -= 1
	elif int(qr[1]) > Os:
		res.append(0)
	else:
		res.append(1)
for val in res:
	print(val)


(n, q) = map(int, input().split())
num = list(map(int, input().split()))
l = []
for i in range(q):
	l.append([int(j) for j in input().split()])
total = num.count(1)
for i in range(q):
	if l[i][0] == 1:
		if num[l[i][1] - 1] == 1:
			num[l[i][1] - 1] ^= 1
			total -= 1
		else:
			num[l[i][1] - 1] ^= 1
			total += 1
	elif l[i][1] <= total:
		print('1')
	else:
		print('0')


nq = list(map(int, input().split()))
(n, q) = (nq[0], nq[1])
arr = list(map(int, input().split()))
ones = 0
for number in arr:
	if number == 1:
		ones += 1
for _ in range(q):
	tm = list(map(int, input().split()))
	(t, m) = (tm[0], tm[1])
	if t == 1:
		if arr[m - 1] == 1:
			arr[m - 1] = 0
			ones -= 1
		else:
			arr[m - 1] = 1
			ones += 1
	elif t == 2:
		if m > ones:
			print('0')
		else:
			print('1')


from collections import Counter

def k_max(arr, com):
	cnt = Counter(arr)
	for (t, k) in com:
		if t == 1:
			if arr[k - 1] == 0:
				arr[k - 1] = 1
				cnt[1] += 1
				cnt[0] -= 1
			else:
				arr[k - 1] = 0
				cnt[0] += 1
				cnt[1] -= 1
		elif k <= cnt[1]:
			print(1)
		else:
			print(0)
(n, q) = (int(i) for i in input().split())
arr = [int(i) for i in input().split()]
commands = []
for i in range(q):
	(t, k) = (int(i) for i in input().split())
	commands.append((t, k))
k_max(arr, commands)


def main():
	(n, q) = map(int, input().split())
	a_array = list(map(int, input().split()))
	one_count = sum(a_array)
	count = [n - one_count, one_count]
	for i in range(q):
		(t, m) = map(int, input().split())
		if t == 1:
			x = m - 1
			count[0] += 2 * a_array[x] - 1
			count[1] += 1 - 2 * a_array[x]
			a_array[x] = 1 - a_array[x]
		elif t == 2:
			print(1 if m <= count[1] else 0)
main()


(n, q) = map(int, input().split())
l1 = list(map(int, input().split()))
num = 0
for _ in l1:
	if _ == 1:
		num += 1
for i in range(q):
	(t, x) = map(int, input().split())
	if t == 1 and 1 - l1[x - 1] == 0:
		num -= 1
		l1[x - 1] = 0
	elif t == 1 and 1 - l1[x - 1] == 1:
		num += 1
		l1[x - 1] = 1
	elif t == 2 and x <= num:
		print(1)
	elif t == 2 and x > num:
		print(0)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ones = a.count(1)
for _ in range(k):
	(t, x) = map(int, input().split())
	if t == 1:
		a[x - 1] = 1 - a[x - 1]
		if a[x - 1] == 1:
			ones += 1
		else:
			ones -= 1
	elif ones >= x:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a = [int(i) for i in input().split()]
sm = sum(a)
for _ in range(q):
	(t, i) = map(int, input().split())
	if t == 1:
		sm -= a[i - 1]
		a[i - 1] ^= 1
		sm += a[i - 1]
	else:
		print(1 if i <= sm else 0)


import sys
input = sys.stdin.readline
from sys import stdin, stdout
from collections import defaultdict, Counter
M = 10 ** 9 + 7

def main():
	(n, q) = [int(s) for s in input().split()]
	l = [int(s) for s in input().split()]
	num1 = 0
	for i in range(n):
		if l[i] == 1:
			num1 += 1
	for i in range(q):
		(t, x) = [int(s) for s in input().split()]
		if t == 1:
			if l[x - 1] == 0:
				num1 += 1
				l[x - 1] = 1
			else:
				num1 -= 1
				l[x - 1] = 0
		elif num1 >= x:
			print(1)
		else:
			print(0)
main()


n = input().split()
lista = input().split()
ones = lista.count('1')
for c in range(int(n[1])):
	ent = input().split()
	(a, b) = (int(ent[0]), int(ent[1]))
	if a == 1:
		if lista[b - 1] == '1':
			ones -= 1
		elif lista[b - 1] == '0':
			ones += 1
		lista[b - 1] = str(1 - int(lista[b - 1]))
	elif a == 2:
		print(0) if b > ones else print(1)


try:
	(n, q) = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	io = a.count(1)
	for i in range(0, n):
		(t, s) = list(map(int, input().split(' ')))
		if t == 1:
			if a[s - 1] == 1:
				io -= 1
				a[s - 1] = 0
			else:
				io += 1
				a[s - 1] = 1
		elif s > io:
			print(0)
		else:
			print(1)
except:
	pass


def inverte(x):
	return 1 - x
(tamanho, operacoes) = map(int, input().split(' '))
respostas = []
array = input().split(' ')
array = [int(x) for x in array]
ones = array.count(1)
for i in range(operacoes):
	(tipo, v) = map(int, input().split(' '))
	if tipo == 1:
		array[v - 1] = inverte(array[v - 1])
		if array[v - 1] == 1:
			ones += 1
		else:
			ones -= 1
	elif v > ones:
		respostas.append(0)
	else:
		respostas.append(1)
for j in respostas:
	print(j)


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
ceros = 0
ones = 0
for i in range(n):
	if ar[i] == 1:
		ones += 1
	else:
		ceros += 1
for i in range(m):
	c = list(map(int, input().split()))
	if c[0] == 1:
		if ar[c[1] - 1] == 1:
			ones -= 1
			ceros += 1
		else:
			ceros -= 1
			ones += 1
		ar[c[1] - 1] ^= 1
	elif ones >= c[1]:
		print(1)
	else:
		print(0)


(n, r) = [int(k) for k in input().split()]
a = [int(k) for k in input().split()]
z = 0
o = 0
for ele in a:
	if ele == 0:
		z += 1
	else:
		o += 1
for i in range(r):
	(t, x) = [int(k) for k in input().split()]
	if t == 1:
		if a[x - 1] == 0:
			a[x - 1] = 1
			z -= 1
			o += 1
		else:
			a[x - 1] = 0
			z += 1
			o -= 1
	if t == 2:
		if x <= o:
			print(1)
		else:
			print(0)


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
cnt = sum(arr)
for _ in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if arr[x - 1]:
			cnt -= 1
		else:
			cnt += 1
		arr[x - 1] = 1 - arr[x - 1]
	elif cnt >= x:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

def get_list_ints():
	return list(map(int, input().split()))

def get_char_list():
	s = input()
	return list(s[:len(s) - 1])

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def bs(data, elem):
	low = 0
	high = len(data) - 1
	while low <= high:
		middle = (low + high) // 2
		if data[middle] == elem:
			return middle
		elif data[middle] > elem:
			high = middle - 1
		else:
			low = middle + 1
	return -1

def main():
	(n, q) = get_tuple_ints()
	a = get_list_ints()
	k = a.count(1)
	for _ in range(q):
		(t, x) = get_tuple_ints()
		if t == 1:
			if a[x - 1] == 1:
				a[x - 1] = 0
				k -= 1
				continue
			elif a[x - 1] == 0:
				a[x - 1] = 1
				k += 1
				continue
		elif x <= k:
			print(1)
			continue
		else:
			print(0)
			continue
main()


(n, q) = list(map(int, input().split()))
a = list(map(int, input().split()))
ones = 0
for i in a:
	if i:
		ones += 1
zeros = n - ones
for _ in range(q):
	(t, k) = list(map(int, input().split()))
	if t == 1:
		if a[k - 1] == 1:
			ones -= 1
			zeros += 1
			a[k - 1] = 0
		else:
			ones += 1
			zeros -= 1
			a[k - 1] = 1
	elif k <= ones:
		print('1')
	else:
		print('0')


import sys
input = sys.stdin.readline
(n, q) = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
zero = 0
one = 0
for i in l:
	if i == 0:
		zero += 1
	else:
		one += 1
for i in range(q):
	(a, b) = list(map(int, input().split(' ')))
	if a == 1:
		if l[b - 1] == 0:
			zero -= 1
			one += 1
		else:
			zero += 1
			one -= 1
		l[b - 1] = 1 - l[b - 1]
	elif one >= b:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
lis = list(map(int, input().split()))
one = lis.count(1)
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		lis[b - 1] = 1 - lis[b - 1]
		one = one - 1 if not lis[b - 1] else one + 1
	else:
		print(1) if one >= b else print(0)


(n, q) = list(map(int, input().split()))
x = list(map(int, input().split()))
a = x.count(1)
b = n - a
for i in range(q):
	(m, n) = list(map(int, input().split()))
	if m == 1:
		if x[n - 1] == 1:
			b += 1
			a -= 1
			x[n - 1] = 0
		else:
			b -= 1
			a += 1
			x[n - 1] = 1
	elif n <= a:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
ans = arr.count(1)
for _ in range(q):
	(t, k) = map(int, input().split(' '))
	if t == 1:
		if arr[k - 1] == 0:
			ans += 1
			arr[k - 1] = 1
		else:
			arr[k - 1] = 0
			ans -= 1
	elif k > ans:
		print(0)
	else:
		print(1)


(n, q) = map(int, input().split())
w = list(list(map(int, input().split())))
z = w.count(0)
x = n - z
for i in range(q):
	(t, k) = map(int, input().split())
	if t == 1:
		w[k - 1] = 1 - w[k - 1]
		if w[k - 1] == 0:
			x -= 1
			z += 1
		else:
			x += 1
			z -= 1
	elif x >= k:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
count = sum(arr)
for _ in range(q):
	(t, kx) = map(int, input().split())
	if t == 1:
		arr[kx - 1] = 1 - arr[kx - 1]
		if arr[kx - 1] == 1:
			count += 1
		else:
			count -= 1
	elif count >= kx:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
zero = a.count(0)
one = n - zero
for i in range(q):
	(t, l) = map(int, input().split())
	if t == 1:
		if a[l - 1]:
			zero += 1
			one -= 1
			a[l - 1] = 0
		else:
			zero -= 1
			one += 1
			a[l - 1] = 1
	elif l <= one:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
zero = a.count(0)
one = n - zero
for _ in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if a[x - 1] == 1:
			zero += 1
			one -= 1
			a[x - 1] = 0
		else:
			zero -= 1
			one += 1
			a[x - 1] = 1
	elif x <= one:
		print(1)
	else:
		print(0)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	(N, Q) = map(int, input().split())
	A = list(map(int, input().split()))
	cnt = [A.count(0), A.count(1)]
	for _ in range(Q):
		(t, x) = map(int, input().split())
		if t == 1:
			a = A[x - 1]
			cnt[a] -= 1
			cnt[a ^ 1] += 1
			A[x - 1] ^= 1
		elif x <= cnt[1]:
			print(1)
		else:
			print(0)
main()


import sys
(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
(n0, n1) = (arr.count(0), arr.count(1))
for line in sys.stdin:
	(op, v) = map(int, line.split())
	if op == 1:
		arr[v - 1] = 1 - arr[v - 1]
		if arr[v - 1] == 0:
			n1 -= 1
			n0 += 1
		else:
			n0 -= 1
			n1 += 1
	else:
		print(1 if v <= n1 else 0)


R = lambda : map(int, input().split())
(n, q) = R()
(*a,) = R()
r = sum(a)
for _ in [0] * q:
	(t, x) = R()
	if t < 2:
		a[x - 1] ^= 1
		r += 2 * a[x - 1] - 1
	else:
		print(+(x <= r))


import sys
input = lambda : sys.stdin.readline().rstrip()
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
for _ in range(q):
	(t, k) = map(int, input().split())
	if t == 1:
		s += 1 - 2 * A[k - 1]
		A[k - 1] = 1 - A[k - 1]
	else:
		ans = 0
		if s >= k:
			ans = 1
		print(ans)


import sys
input = sys.stdin.readline

def solution(n, q, arr, queries):
	count_1 = len([1 for elem in arr if elem == 1])
	for [type_, pos] in queries:
		if type_ == 1:
			if arr[pos - 1] == 1:
				count_1 -= 1
			else:
				count_1 += 1
			arr[pos - 1] = 1 - arr[pos - 1]
		elif count_1 >= pos:
			print(1)
		else:
			print(0)
(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
queries = [list(map(int, input().split())) for _ in range(q)]
solution(n, q, arr, queries)


import sys
import math
input = sys.stdin.readline
[n, q] = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
s = sum(a)
for t in range(q):
	[c, d] = list(map(int, input().split(' ')))
	if c == 1:
		if a[d - 1] == 1:
			s -= 1
			a[d - 1] = 0
		else:
			s += 1
			a[d - 1] = 1
	elif s >= d:
		print(1)
	else:
		print(0)


from sys import stdin as sin

def aint():
	return int(input())

def amap():
	return map(int, sin.readline().split())

def alist():
	return list(map(int, sin.readline().split()))

def astr():
	return input()
(n, q) = amap()
l = alist()
o = 0
z = 0
for i in l:
	if i == 1:
		o += 1
	else:
		z += 1
for i in range(q):
	(a, b) = amap()
	if a == 2:
		if o < b:
			print(0)
		else:
			print(1)
	elif l[b - 1] == 1:
		l[b - 1] = 0
		z += 1
		o -= 1
	else:
		l[b - 1] = 1
		z -= 1
		o += 1


nq = input().split()
n = int(nq[0])
q = int(nq[1])
arr = [int(x) for x in input().split()]
one = 0
for i in range(n):
	if arr[i] == 1:
		one += 1
for i in range(q):
	qi = input().split()
	query = int(qi[0])
	ind = int(qi[1])
	if query == 1:
		if arr[ind - 1] == 0:
			one += 1
			arr[ind - 1] = 1 - arr[ind - 1]
		else:
			one -= 1
			arr[ind - 1] = 1 - arr[ind - 1]
	elif one >= ind:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline
from collections import Counter
(n, q) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
c = Counter(a)
num_0 = c[0]
num_1 = c[1]
for _ in range(q):
	(cmd, k) = map(int, input().strip().split())
	if cmd == 1:
		k -= 1
		if a[k] == 0:
			num_0 -= 1
			num_1 += 1
		else:
			num_0 += 1
			num_1 -= 1
		a[k] = 1 - a[k]
	elif num_1 >= k:
		print(1)
	else:
		print(0)


(a, b) = map(int, input().split())
arr = list(map(int, input().split()))
l = arr.count(0)
k = a - l
for _ in range(b):
	(m, n) = map(int, input().split())
	if m == 1:
		if arr[n - 1] == 0:
			l -= 1
			k += 1
			arr[n - 1] = 1
		else:
			l += 1
			k -= 1
			arr[n - 1] = 0
	elif n <= k:
		print(1)
	else:
		print(0)


import bisect
import math
import itertools
import sys
alpha = 'abcdefghijklmnopqrstuvwxyz'

def solve(n, q, arr, qs):
	zeros = int(arr.count(0))
	for j in range(q):
		if qs[j][0] == 1:
			x = qs[j][1]
			if arr[x - 1]:
				zeros += 1
			else:
				zeros -= 1
			arr[x - 1] = 1 - arr[x - 1]
		if qs[j][0] == 2:
			k = qs[j][1]
			if k <= n - zeros:
				print(1)
			else:
				print(0)
	pass
t = 1
ans = []
for _ in range(t):
	(n, q) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	qs = []
	for j in range(q):
		qs.append([int(x) for x in input().split()])
	ans.append(solve(n, q, arr, qs))


(x, y) = (0, 0)
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == 0:
		x += 1
	else:
		y += 1
for i in range(q):
	(t, m) = map(int, input().split())
	if t == 1:
		if a[m - 1] == 1:
			a[m - 1] = 0
			x = x + 1
			y = y - 1
		elif a[m - 1] == 0:
			a[m - 1] = 1
			x = x - 1
			y = y + 1
	elif t == 2:
		if m > y:
			print(0)
		else:
			print(1)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		(n, q) = invr()
		a = inlt()
		(one, zero) = (0, 0)
		for i in a:
			if i == 1:
				one += 1
		for i in range(q):
			(t, qq) = invr()
			if t == 1:
				qq -= 1
				if a[qq] == 0:
					one += 1
					a[qq] = 1
				else:
					one -= 1
					a[qq] = 0
			elif qq > one:
				print('0')
			else:
				print('1')
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


temp = [int(x) for x in input().split()]
n = temp[0]
q = temp[1]
a = [int(x) for x in input().split()]
o = a.count(1)
for i in range(q):
	temp = [int(x) for x in input().split()]
	t = temp[0]
	if t == 1:
		x = temp[1]
		if a[x - 1] == 0:
			o += 1
		else:
			o -= 1
		a[x - 1] = 1 - a[x - 1]
	else:
		k = temp[1]
		if k <= o:
			print(1)
		else:
			print(0)


import sys
n = [int(i) for i in sys.stdin.readline().split()]
m = [int(i) for i in sys.stdin.readline().split()]
k = m.count(1)
for _ in range(n[1]):
	a = [int(i) for i in sys.stdin.readline().split()]
	if a[0] == 1:
		if m[a[1] - 1] == 1:
			m[a[1] - 1] = 0
			k = k - 1
		else:
			m[a[1] - 1] = 1
			k = k + 1
	elif a[1] <= k:
		sys.stdout.write('1' + '\n')
	else:
		sys.stdout.write('0' + '\n')


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
z = l.count(0)
o = n - z
for _ in range(q):
	(t, k) = map(int, input().split())
	if t == 1:
		if l[k - 1] == 1:
			z += 1
			o -= 1
			l[k - 1] = 0
		else:
			z -= 1
			o += 1
			l[k - 1] = 1
	if t == 2:
		if k <= o:
			print(1)
		else:
			print(0)


import sys

def k_largest_value(seq, k):
	num_one = sum(seq)
	if num_one >= k:
		return 1
	else:
		return 0
(n, q) = [int(i) for i in sys.stdin.readline().split()]
ls = [int(i.strip()) for i in sys.stdin.readline().split()]
total = sum(ls)
for _ in range(q):
	(t, x) = [int(i) for i in sys.stdin.readline().split()]
	if t == 1:
		if ls[x - 1] == 0:
			ls[x - 1] = 1
			total += 1
		else:
			ls[x - 1] = 0
			total -= 1
	elif total >= x:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a = [int(j) for j in input().split()]
c = a.count(1)
for i in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		c -= a[x - 1]
		a[x - 1] = 1 - a[x - 1]
		c += a[x - 1]
	else:
		print('0' if x > c else '1')


(n, q) = tuple(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
res = []
max_count = 0
for x in a:
	if x == 1:
		max_count += 1
for i in range(0, q):
	(t, x) = tuple(map(int, input().split(' ')))
	if t == 1:
		if a[x - 1] == 1:
			max_count -= 1
		else:
			max_count += 1
		a[x - 1] = 1 - a[x - 1]
	elif x <= max_count:
		res.append(1)
	else:
		res.append(0)
print(*res, sep='\n')


(n, q) = map(int, input().split())
l = [int(x) for x in input().split()]
x = l.count(1)
w = []
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 2:
		if b <= x:
			w.append(1)
		else:
			w.append(0)
	elif l[b - 1] == 0:
		l[b - 1] = 1
		x += 1
	else:
		l[b - 1] = 0
		x -= 1
for i in w:
	print(i)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
o = a.count(1)
z = a.count(0)
for _ in range(q):
	(t, p) = map(int, input().split())
	if t == 1:
		if a[p - 1] == 0:
			z -= 1
			o += 1
			a[p - 1] = 1
		else:
			z += 1
			o -= 1
			a[p - 1] = 0
	elif p > o:
		print(0)
	else:
		print(1)


import sys
import math

class DictList(dict):

	def __setitem__(self, key, value):
		try:
			self[key].append(value)
		except KeyError:
			super(DictList, self).__setitem__(key, value)
		except AttributeError:
			super(DictList, self).__setitem__(key, [self[key], value])

def fn(n, q, x, a, b):
	c = x.count(1)
	d = x.count(0)
	for i in range(q):
		if a[i] == 1:
			if x[b[i] - 1] == 1:
				x[b[i] - 1] = 0
				c = c - 1
				d = d + 1
			elif x[b[i] - 1] == 0:
				x[b[i] - 1] = 1
				c = c + 1
				d = d - 1
		if a[i] == 2:
			if b[i] > c:
				print(0)
			if b[i] <= c:
				print(1)
input = sys.stdin.read()
data = list(map(int, input.split()))
n = data[0]
q = data[1]
a = data[2:2 + n]
l = 0
x = []
y = []
for i in range(q):
	x.append(data[2 + n + l])
	y.append(data[2 + n + l + 1])
	l = l + 2
fn(n, q, a, x, y)


import math

def getint():
	return [int(i) for i in input().split()]

def getstr():
	return [str(i) for i in input().split()]

def solve():
	(n, q) = getint()
	a = getint()
	ans = a.count(1)
	for i in range(q):
		(t, s) = getint()
		if t == 1:
			if a[s - 1] == 1:
				ans -= 1
			else:
				ans += 1
			a[s - 1] = 1 - a[s - 1]
		elif ans >= s:
			print(1)
		else:
			print(0)
solve()


(length, queries) = input().split(' ')
queries = int(queries)
a = list(map(lambda x: int(x), input().split(' ')))
res = ''
cnt = len(list(filter(lambda x: x == 1, a)))
while queries > 0:
	(cmd, n) = input().split(' ')
	n = int(n) - 1
	if cmd == '1':
		if a[n] == 1:
			a[n] = 1 - a[n]
			cnt -= 1
		else:
			a[n] = 1 - a[n]
			cnt += 1
	elif cmd == '2':
		if cnt > n:
			res = res + '1\n'
		else:
			res = res + '0\n'
	queries -= 1
print(res, end='')


a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
sum0 = 0
sum1 = 0
for q in b:
	if q == 1:
		sum1 = sum1 + 1
	else:
		sum0 = sum0 + 1
for z in range(a[1]):
	c = [int(p) for p in input().split()]
	if c[0] == 1:
		if b[c[1] - 1] == 1:
			b[c[1] - 1] = 0
			sum0 = sum0 + 1
			sum1 = sum1 - 1
		elif b[c[1] - 1] == 0:
			b[c[1] - 1] = 1
			sum1 = sum1 + 1
			sum0 = sum0 - 1
	elif c[1] <= sum1:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
li = list(map(int, input().split()))
count = 0
for i in li:
	if i == 1:
		count = count + 1
for i in range(q):
	(t, y) = map(int, input().split())
	if t == 1:
		li[y - 1] = 1 - li[y - 1]
		if li[y - 1] == 1:
			count = count + 1
		else:
			count = count - 1
	elif count < y:
		print(0)
	else:
		print(1)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = {}
for i in l:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
for i in range(k):
	(a, b) = map(int, input().split())
	if a == 1:
		if l[b - 1] in d:
			if d[l[b - 1]] > 0:
				d[l[b - 1]] -= 1
		l[b - 1] = 1 - l[b - 1]
		if l[b - 1] in d:
			d[l[b - 1]] += 1
		else:
			d[l[b - 1]] = 1
	else:
		c = 0
		for i in range(1, -1000000, -1):
			if i in d:
				if d[i] > 0:
					if d[i] >= b:
						print(i)
						break
					else:
						b -= d[i]


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial, sqrt
from collections import defaultdict, Counter, OrderedDict, deque
from itertools import combinations, permutations
from bisect import *
from functools import reduce
from operator import mul
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().strip('\n')
grid = lambda r: [lint() for i in range(r)]
localsys = 0
start_time = time.time()
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)

def ceill(n, x):
	return (n + x - 1) // x
T = False

def solve():
	(n, m) = lint()
	a = lint()
	(zero, one) = (0, 0)
	for i in a:
		if i == 1:
			one += 1
		else:
			zero += 1
	for _ in range(m):
		(t, x) = lint()
		if t == 1:
			if a[x - 1] == 1:
				zero += 1
				one -= 1
				a[x - 1] = 0
			else:
				a[x - 1] = 1
				zero -= 1
				one += 1
		elif x <= one:
			print(1)
		else:
			print(0)

def run():
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
run()
T = I() if T else 1
for _ in range(T):
	solve()
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


key = list(map(int, input().split()))
arr = list(map(int, input().split()))
q = key[1]
sume = sum(arr)
for i in range(q):
	grr = list(map(int, input().split()))
	t = grr[0]
	k = grr[1]
	if t == 1:
		if arr[k - 1] == 1:
			sume -= 1
			arr[k - 1] = 0
		else:
			sume += 1
			arr[k - 1] = 1
	elif sume >= k:
		print('1')
	else:
		print('0')


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
b = a.copy()
a.sort()
idx = sum(a)
for i in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if b[x - 1] == 0:
			idx += 1
			b[x - 1] = 1
		else:
			idx -= 1
			b[x - 1] = 0
	else:
		d = idx
		if x > d:
			print(0)
		else:
			print(1)


def answer(type, xk, ary, sum):
	if type == 1:
		ary[xk - 1] = 1 - ary[xk - 1]
		if ary[xk - 1] == 0:
			sum -= 1
		else:
			sum += 1
	elif xk <= sum:
		print(1)
	else:
		print(0)
	return sum

def main():
	(n, q) = [int(i) for i in input().split()]
	ary = [int(i) for i in input().split()]
	type = [0] * q
	xk = [0] * q
	for j in range(q):
		(type[j], xk[j]) = [int(i) for i in input().split()]
	sum = 0
	for e in ary:
		sum += e
	for j in range(q):
		sum = answer(type[j], xk[j], ary, sum)
main()


(n, n2) = list(map(int, input().split()))
a = list(map(int, input().split()))
one_count = a.count(1)
for _ in range(n2):
	(t, q) = list(map(int, input().split()))
	if t == 1:
		if a[q - 1] == 1:
			one_count -= 1
		else:
			one_count += 1
		a[q - 1] = 1 - a[q - 1]
	elif t == 2:
		if q <= one_count:
			print(1)
		else:
			print(0)


import sys
(n, p) = map(int, sys.stdin.readline().split())
nums = list(map(int, sys.stdin.readline().split()))
sum = sum(nums)
for _ in range(p):
	(t, num) = map(int, sys.stdin.readline().split())
	if t == 1:
		sum -= nums[num - 1]
		nums[num - 1] = 1 - nums[num - 1]
		sum += nums[num - 1]
	elif num <= sum:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a = [int(i) for i in input().split()]
ans = []
cnt = sum(a)
for _ in range(q):
	(t, p) = map(int, input().split())
	if t == 1:
		if a[p - 1] == 0:
			cnt += 1
		else:
			cnt -= 1
		a[p - 1] = 1 - a[p - 1]
	elif p > cnt:
		ans.append(0)
	else:
		ans.append(1)
for i in ans:
	print(i)


answer_list = []
q = input().split()
q = q[1]
n_list = input().split()
n_0 = 0
n_1 = 0
for l in n_list:
	if l == '0':
		n_0 += 1
	else:
		n_1 += 1
for a in range(int(q)):
	numbers = input().split()
	first = int(numbers[0])
	second = int(numbers[1])
	if first == 1:
		if n_list[second - 1] == '0':
			n_list[second - 1] = '1'
			n_0 -= 1
			n_1 += 1
		else:
			n_list[second - 1] = '0'
			n_0 += 1
			n_1 -= 1
	elif n_1 >= second:
		answer_list.append(1)
	else:
		answer_list.append(0)
for w in answer_list:
	print(w)


def main():
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	ones = arr.count(1)
	zeroes = arr.count(0)
	ans = []
	for i in range(q):
		(t, x) = map(int, input().split())
		if t == 1:
			if arr[x - 1] == 0:
				arr[x - 1] = 1
				zeroes -= 1
				ones += 1
			else:
				arr[x - 1] = 0
				zeroes += 1
				ones -= 1
		elif ones >= x:
			ans.append('1')
		else:
			ans.append('0')
	print('\n'.join(ans))
main()


(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
ones = arr.count(1)
s = []
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 2:
		if b <= ones:
			s.append(1)
		else:
			s.append(0)
	elif arr[b - 1] == 0:
		arr[b - 1] = 1
		ones = ones + 1
	else:
		arr[b - 1] = 0
		ones = ones - 1
for i in s:
	print(i)


from __future__ import division, print_function
import math
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def main():
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	c1 = arr.count(1)
	for i in range(q):
		(t, query) = map(int, input().split())
		if t == 2:
			if c1 >= query:
				print(1)
			else:
				print(0)
		else:
			if arr[query - 1] == 1:
				c1 -= 1
			else:
				c1 += 1
			arr[query - 1] = 1 - arr[query - 1]
main()


(n, q) = map(int, input().split())
w = list(map(int, input().split()))
e = w.count(1)
for i in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		w[x - 1] = 1 - w[x - 1]
		if w[x - 1] == 1:
			e += 1
		else:
			e -= 1
	else:
		print(int(e >= x))


import sys, io, os, math
from math import ceil, log, gcd, sqrt
from itertools import permutations
import operator
mod = 1000000007
mod1 = 998244353

def intinp():
	return int(sys.stdin.readline())

def strinp():
	return sys.stdin.readline()

def arrinp():
	return list(map(int, sys.stdin.readline().strip().split()))

def mulinp():
	return map(int, sys.stdin.readline().strip().split())

def flush():
	return stdout.flush()

def power_two(x):
	return 1 << x

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	(n, q) = mulinp()
	t = arrinp()
	count = 0
	for i in range(0, n):
		if t[i]:
			count += 1
	while q:
		(x, k) = mulinp()
		if x == 1:
			t[k - 1] = 1 - t[k - 1]
			if t[k - 1] == 0:
				count -= 1
			else:
				count += 1
		if x == 2:
			if k <= count:
				print(1)
			else:
				print(0)
		q -= 1

def main():
	tc = 1
	while tc:
		solve()
		tc -= 1
main()


import sys
input = sys.stdin.readline
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
ONES = sum(A)
for i in range(q):
	(qu, x) = map(int, input().split())
	if qu == 1:
		x -= 1
		if A[x] == 0:
			A[x] = 1
			ONES += 1
		else:
			A[x] = 0
			ONES -= 1
	elif ONES >= x:
		print(1)
	else:
		print(0)


q = int(input().split()[1])
x = list(input().split())
ones = x.count('1')
for _ in range(0, q):
	(f, v) = input().split()
	if f == '2':
		if ones >= int(v):
			print(1)
		else:
			print(0)
	else:
		v = int(v)
		if x[v - 1] == '1':
			ones -= 1
			x[v - 1] = '0'
		else:
			ones += 1
			x[v - 1] = '1'


(n, q) = map(int, input().split())
a = [int(x) for x in input().split()]
d = {0: 0, 1: 0}
for i in a:
	d[i] += 1
for _ in range(q):
	(x, y) = map(int, input().split())
	if x == 1:
		y -= 1
		d[a[y]] -= 1
		a[y] = 1 - a[y]
		d[a[y]] += 1
	elif d[1] >= y:
		print(1)
	else:
		print(0)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def solve():
	(n, q) = map(int, input().split())
	L = list(map(int, input().split()))
	ones = sum(L)
	for i in range(q):
		(t, x) = map(int, input().split())
		if t == 2:
			if ones >= x:
				print(1)
			else:
				print(0)
		else:
			if L[x - 1] == 1:
				ones -= 1
			else:
				ones += 1
			L[x - 1] ^= 1
solve()


(n, q) = map(int, input().split())
k = list(map(int, input().split()))
m = k.count(0)
f = n - m
ans = []
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		if k[b - 1] == 1:
			k[b - 1] = 0
			m = m + 1
			f = f - 1
		else:
			k[b - 1] = 1
			f = f + 1
			m = m - 1
	elif n - b < m:
		ans.append(0)
	else:
		ans.append(1)
print(*ans, sep='\n')


from sys import stdin
input = stdin.buffer.readline
(n, q) = map(int, input().split())
arr = [int(x) for x in input().split()]
o = arr.count(1)
z = arr.count(0)
for i in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if arr[x - 1] == 0:
			arr[x - 1] = 1
			z = z - 1
			o = o + 1
		else:
			arr[x - 1] = 0
			z = z + 1
			o = o - 1
	elif x > o:
		print(0)
	else:
		print(1)


import sys
(n, q) = map(int, sys.stdin.readline().split(' '))
ar = [-1] + list(map(int, sys.stdin.readline().split(' ')))
n1 = ar.count(1)
n0 = ar.count(0)
for _ in range(q):
	(t, k) = map(int, sys.stdin.readline().split(' '))
	if t == 1:
		if ar[k] == 1:
			ar[k] = 0
			n0 += 1
			n1 -= 1
		else:
			ar[k] = 1
			n0 -= 1
			n1 += 1
	elif k > n1:
		print(0)
	else:
		print(1)


import sys
input = sys.stdin.readline

def solve():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	c = [0, 0]
	r = []
	for i in a:
		c[i] += 1
	for i in range(q):
		(t, x) = map(int, input().split())
		if t == 1:
			x -= 1
			v = a[x]
			c[v] -= 1
			v ^= 1
			c[v] += 1
			a[x] = v
		else:
			x -= 1
			r.append(str(int(x < c[1])))
	print('\n'.join(r))
solve()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	(n, qs) = inlt()
	ar = inlt()
	onesCount = 0
	for val in ar:
		if val == 1:
			onesCount += 1
	for q in range(qs):
		(t, value) = inlt()
		if t == 1:
			value -= 1
			if ar[value] == 1:
				onesCount -= 1
			else:
				onesCount += 1
			ar[value] = 1 - ar[value]
		elif onesCount >= value:
			print('1')
		else:
			print('0')
main()


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
for i in range(q):
	(h, k) = map(int, input().split())
	if h == 1:
		y = a[k - 1]
		if y == 1:
			s -= 1
		else:
			s += 1
		a[k - 1] = 1 - a[k - 1]
	elif s >= k:
		print(1)
	else:
		print(0)


(n, q) = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
one = a.count(1)
for i in range(q):
	(t, x) = (int(i) for i in input().split())
	if t == 2:
		if one >= x:
			print(1)
		else:
			print(0)
	if t == 1:
		if a[x - 1] == 1:
			a[x - 1] = 0
			one -= 1
		else:
			a[x - 1] = 1
			one += 1


def solve(arr, query):
	ones = sum(arr)
	for x in query:
		if x[0] == 1:
			if arr[x[1] - 1] == 1:
				ones -= 1
				arr[x[1] - 1] = 0
			else:
				arr[x[1] - 1] = 1
				ones += 1
		elif ones >= x[1]:
			print(1)
		else:
			print(0)
(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
query = []
for _ in range(q):
	(a, b) = map(int, input().split())
	query.append((a, b))
solve(arr, query)


integers = input().split()
arrayLength = int(integers[0])
queries = int(integers[1])
array = input().split()
qtd1 = array.count('1')
for num in range(queries):
	numbers = input().split()
	querie = int(numbers[0])
	position = int(numbers[1])
	if querie == 1:
		if array[position - 1] == '1':
			array[position - 1] = '0'
			qtd1 -= 1
		else:
			array[position - 1] = '1'
			qtd1 += 1
	elif querie == 2:
		if qtd1 >= position:
			print(1)
		else:
			print(0)


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def func(array):
	pass

def main():
	(n, q) = [int(i) for i in parse_input().split()]
	array = [int(i) for i in parse_input().split()]
	counter = Counter(array)
	for _ in range(q):
		(t, x) = [int(i) for i in parse_input().split()]
		if t == 1:
			if array[x - 1] == 1:
				array[x - 1] = 0
				counter[1] -= 1
				counter[0] += 1
			else:
				array[x - 1] = 1
				counter[1] += 1
				counter[0] -= 1
		if t == 2:
			if x <= counter[1]:
				print(1)
			else:
				print(0)
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = input().split()
n = int(n)
k = int(k)
a = input().split()
a = [int(x) for x in a]
a1 = 0
for i in range(n):
	if a[i] == 1:
		a1 += 1
for i in range(k):
	(t, x) = input().split()
	t = int(t)
	x = int(x)
	if t == 1:
		if a[x - 1] == 1:
			a[x - 1] = 0
			a1 -= 1
		else:
			a[x - 1] = 1
			a1 += 1
	elif a1 >= x:
		print(1)
	else:
		print(0)


import sys
input = sys.stdin.readline

def main():
	(n, q) = map(int, input().split())
	alst = list(map(int, input().split()))
	zero = alst.count(0)
	one = n - zero
	for _ in range(q):
		(t, x) = map(int, input().split())
		if t == 1:
			x -= 1
			if alst[x] == 0:
				zero -= 1
				one += 1
			else:
				zero += 1
				one -= 1
			alst[x] = 1 - alst[x]
		elif one >= x:
			print(1)
		else:
			print(0)
for _ in range(1):
	main()


(n, q) = input().split()
n = int(n)
q = int(q)
a = [int(i) for i in input().split()]
b = a.count(1)
for i in range(q):
	(x, y) = input().split()
	x = int(x)
	y = int(y)
	if x == 1:
		a[y - 1] = 1 - a[y - 1]
		if a[y - 1] == 1:
			b += 1
		else:
			b -= 1
	if x == 2:
		if y <= b:
			print('1')
		else:
			print('0')


from collections import *
import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = 1
for k in range(t):
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))[:n]
	zero = a.count(0)
	one = a.count(1)
	for i in range(q):
		(t, option) = map(int, input().split())
		if t == 1:
			a[option - 1] = a[option - 1] ^ 1
			if a[option - 1] == 1:
				one += 1
				zero -= 1
			else:
				zero += 1
				one -= 1
		if t == 2:
			if one >= option:
				print(1)
			else:
				print(0)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
k1 = a.count(1)
for i in range(q):
	(b, c) = map(int, input().split())
	if b == 1:
		if a[c - 1] == 0:
			k1 += 1
			a[c - 1] = 1
		else:
			k1 -= 1
			a[c - 1] = 0
	elif k1 >= c:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
array = list(map(int, input().split()))
count_0 = array.count(0)
count_1 = array.count(1)
for _ in range(q):
	(query, k) = map(int, input().split())
	if query == 2:
		if k <= count_1:
			print(1)
		else:
			print(0)
	if query == 1:
		if array[k - 1] == 1:
			count_1 -= 1
			count_0 += 1
		else:
			count_0 -= 1
			count_1 += 1
		array[k - 1] = 1 - array[k - 1]


(size, requests) = map(int, input().split())
(one, zero) = (0, 0)
array = []
line = input().split()
for i in line:
	array.append(int(i))
	if int(i) == 1:
		one += 1
	else:
		zero += 1
for i in range(requests):
	line = input().split()
	(f, s) = (int(line[0]), int(line[1]))
	if f == 1:
		if array[s - 1] == 1:
			one -= 1
			zero += 1
		else:
			one += 1
			zero -= 1
		array[s - 1] = 1 - array[s - 1]
	elif s > one:
		print(0)
	else:
		print(1)


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
query = []
for i in range(q):
	query.append(list(map(int, input().split())))
num_zero = 0
num_one = 0
for i in arr:
	if i == 0:
		num_zero += 1
	else:
		num_one += 1
for i in query:
	if i[0] == 2:
		k = i[1]
		if k <= num_one:
			print(1)
		else:
			print(0)
	elif arr[i[1] - 1] == 1:
		num_one -= 1
		num_zero += 1
		arr[i[1] - 1] = 0
	else:
		num_zero -= 1
		num_one += 1
		arr[i[1] - 1] = 1


from sys import stdin
(n, q) = [int(x) for x in stdin.readline().split()]
nums = [int(x) for x in stdin.readline().split()]
ones = sum(nums)
for _ in range(q):
	(t, x) = [int(x) for x in stdin.readline().split()]
	if t == 1:
		x -= 1
		if nums[x] == 1:
			ones -= 1
		else:
			ones += 1
		nums[x] = 1 - nums[x]
	elif x <= ones:
		print('1')
	else:
		print('0')


import sys
input = sys.stdin.readline
flush = sys.stdout.flush
from collections import Counter
(n, q) = map(int, input().split())
A = list(map(int, input().split()))
cnt = Counter(A)
for _ in range(q):
	(a, i) = map(int, input().split())
	if a == 1:
		i -= 1
		x = A[i]
		cnt[x] -= 1
		cnt[1 - x] += 1
		A[i] ^= 1
	elif cnt[1] >= i:
		print(1)
	else:
		print(0)


import sys, io, os, time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'

def ceil(num, denom):
	return (num + denom - 1) // denom
input = sys.stdin.readline
(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
count = Counter(arr)
for qq in range(q):
	(t, ind) = map(int, input().split())
	if t == 1:
		if arr[ind - 1] == 1:
			arr[ind - 1] = 0
			count[1] -= 1
			count[0] += 1
		else:
			arr[ind - 1] = 1
			count[1] += 1
			count[0] -= 1
	elif ind <= count[1]:
		print(1)
	else:
		print(0)


out = []
(n, q) = map(int, input().split())
l = list(map(int, input().split()))
o = sum([1 for x in l if x == 1])
for _ in range(q):
	(t, p) = map(int, input().split())
	if t == 1:
		if l[p - 1] == 1:
			o -= 1
			l[p - 1] = 0
		else:
			o += 1
			l[p - 1] = 1
	elif o >= p:
		out.append(1)
	else:
		out.append(0)
for i in out:
	print(i)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
tot = sum(a)
for i in range(q):
	(t, b) = map(int, input().split())
	if t == 1:
		a[b - 1] = 1 - a[b - 1]
		if a[b - 1] == 1:
			tot += 1
		else:
			tot -= 1
	elif b <= tot:
		print(1)
	else:
		print(0)


import sys
pin = sys.stdin.readline
(N, Q) = map(int, pin().split())
A = [*map(int, pin().split())]
S = sum(A)
for q in range(Q):
	(t, v) = map(int, pin().split())
	if t == 1:
		if A[v - 1]:
			S -= 1
		else:
			S += 1
		A[v - 1] = 1 - A[v - 1]
	elif t == 2:
		if v > S:
			print(0)
		else:
			print(1)


q = int(input().split()[1])
m = input().split()
list1 = []
yed = m.count('1')
for i in range(q):
	s = input().split()
	if s[0] == '2':
		if int(s[1]) > yed:
			list1.append(0)
		else:
			list1.append(1)
	elif m[int(s[1]) - 1] == '1':
		yed -= 1
		m[int(s[1]) - 1] = '0'
	else:
		yed += 1
		m[int(s[1]) - 1] = '1'
print(*list1, sep='\n')


from sys import stdin, stdout

def gmi():
	return map(int, stdin.readline().strip().split())

def gms():
	return map(str, stdin.readline().strip().split())

def gari():
	return list(map(int, stdin.readline().strip().split()))

def gars():
	return list(map(str, stdin.readline().strip().split()))

def gs():
	return stdin.readline().strip()

def gls():
	return list(stdin.readline())

def gi():
	return int(stdin.readline())

def pr(s):
	return file.write(str(s) + '\n')
(n, q) = gmi()
ar = gari()
c = ar.count(1)
while q:
	q -= 1
	(a, b) = gmi()
	if a == 1:
		ar[b - 1] = 1 - ar[b - 1]
		if ar[b - 1]:
			c += 1
		else:
			c -= 1
	elif b <= c:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
count1 = 0
a = list(map(int, input().split()))
for i in a:
	count1 += i
for j in range(q):
	(t, p) = map(int, input().split())
	if t == 1:
		if a[p - 1] == 1:
			a[p - 1] = 0
			count1 -= 1
		else:
			count1 += 1
			a[p - 1] = 1
	elif p > count1:
		print(0)
	else:
		print(1)


def remove_by_index(l1, k):
	ans = []
	for i in range(len(l1)):
		if i == k:
			continue
		ans.append(l1[i])
	return ans

def get_kth_largest_elem(l1, k):
	index = -1
	for _ in range(k):
		max = -1
		for i in range(len(l1)):
			if l1[i] > max:
				max = l1[i]
				index = i
		l1 = remove_by_index(l1, index)
	return max

def solve(l1, l2):
	cnt_1 = 0
	cnt_0 = 0
	for items in l1:
		if items == 1:
			cnt_1 += 1
		else:
			cnt_0 += 1
	for q in l2:
		if q[0] == 2:
			k = q[1]
			if k > cnt_1:
				print(0)
			else:
				print(1)
		else:
			l1[q[1] - 1] = 1 - l1[q[1] - 1]
			if l1[q[1] - 1]:
				cnt_1 += 1
				cnt_0 -= 1
			else:
				cnt_0 += 1
				cnt_1 -= 1
queries = []
q1 = input().split(' ')
num_query = int(q1[1])
l1 = input().split(' ')
l1 = [int(i) for i in l1]
for _ in range(num_query):
	l22 = input().split(' ')
	l22 = [int(i) for i in l22]
	queries.append([l22[0], l22[1]])
solve(l1, queries)


(n, q) = map(int, input().split())
d = list(map(int, input().split()))
k = d.count(1)
for i in range(q):
	(x, y) = map(int, input().split())
	if x == 1:
		if d[y - 1] == 1:
			d[y - 1] = 0
			k -= 1
		else:
			d[y - 1] = 1
			k += 1
	if x == 2:
		if y <= k:
			print(1)
		else:
			print(0)


import sys
(n, q) = map(int, sys.stdin.readline().strip().split())
a = list(map(int, sys.stdin.readline().strip().split()))
c = a.count(1)
for _ in range(q):
	(t, x) = map(int, sys.stdin.readline().strip().split())
	if t == 1:
		if a[x - 1] == 0:
			c += 1
			a[x - 1] = 1
		elif a[x - 1] == 1:
			c -= 1
			a[x - 1] = 0
	elif t == 2:
		if x > c:
			print(0)
		else:
			print(1)


try:
	(n, q) = map(int, input().split())
	l = [int(x) for x in input().split()]
	m = 0
	for i in range(n):
		if l[i] == 1:
			m += 1
	for i in range(q):
		(tp, r) = map(int, input().split())
		if tp == 1:
			if l[r - 1] == 1:
				l[r - 1] = 0
				m -= 1
			else:
				l[r - 1] = 1
				m += 1
		elif r <= m:
			print(1)
		else:
			print(0)
except EOFError:
	pass


nq = input().split()
n = int(nq[0])
q = int(nq[1])
array = [int(x) for x in input().split()]
qt_ones = array.count(1)
while q > 0:
	txk = input().split()
	t = int(txk[0])
	if t == 1:
		x = int(txk[1])
		array[x - 1] = 1 - array[x - 1]
		if array[x - 1] == 1:
			qt_ones += 1
		elif array[x - 1] == 0:
			qt_ones -= 1
	elif t == 2:
		k = int(txk[1])
		if k <= qt_ones:
			print(1)
		else:
			print(0)
	q -= 1


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
one = sum(a)
for i in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if a[x - 1] == 1:
			one -= 1
			a[x - 1] = 0
		else:
			one += 1
			a[x - 1] = 1
	elif x <= one:
		print(1)
	else:
		print(0)


(t, q) = input().split(' ')
l = []
l = input().split(' ')
f = [0, 0]
for k in l:
	if k == '0':
		f[0] += 1
	else:
		f[1] += 1
for i in range(int(q)):
	(t, x) = input().split(' ')
	if t == '1':
		if l[int(x) - 1] == '1':
			f[1] -= 1
			f[0] += 1
			l[int(x) - 1] = '0'
		else:
			f[1] += 1
			f[0] -= 1
			l[int(x) - 1] = '1'
	elif t == '2':
		if int(x) > f[1]:
			print(0)
		else:
			print(1)


(n, q) = map(int, input().split())
a = list(map(int, input().split()))
(c0, c1) = (0, 0)
for i in a:
	if i == 1:
		c1 += 1
	else:
		c0 += 1
for _ in range(q):
	(x, y) = map(int, input().split())
	if x == 1:
		if a[y - 1] == 1:
			c1 -= 1
			c0 += 1
		else:
			c1 += 1
			c0 -= 1
		a[y - 1] = 1 - a[y - 1]
	elif c1 >= y:
		print(1)
	else:
		print(0)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
q = sum(a)
for i in range(k):
	(w, b) = map(int, input().split())
	if w == 1:
		if a[b - 1] == 1:
			a[b - 1] = 0
			q -= 1
		else:
			a[b - 1] = 1
			q += 1
	elif b > q:
		print(0)
	else:
		print(1)


(len, n) = map(int, input().split())
l = []
output = []
l = list(map(int, input().split()))
one = 0
for i in l:
	if i == 1:
		one += 1
for i in range(n):
	(choice, index) = map(int, input().split())
	if choice == 1:
		if l[index - 1] == 1:
			one -= 1
		else:
			one += 1
		l[index - 1] = 1 - l[index - 1]
	elif choice == 2:
		if index <= one:
			output.append(1)
		else:
			output.append(0)
for i in output:
	print(i)


(n, q) = input().split()
q = int(q)
l = list(map(int, input().split()))
count = l.count(1)
for i in range(q):
	(x, k) = input().split()
	k = int(k)
	x = int(x)
	if x == 2:
		if k <= count:
			print(1)
		else:
			print(0)
	elif l[k - 1] == 0:
		l[k - 1] = 1
		count = count + 1
	else:
		l[k - 1] = 0
		count = count - 1


from sys import stdin, stdout, maxsize
from math import sqrt, log, factorial as ft, gcd
from collections import defaultdict as D, OrderedDict as OD
from bisect import insort
(n, q) = map(int, stdin.readline().strip().split())
a = list(map(int, stdin.readline().strip().split()))
ones = sum(a)
for i in range(q):
	(t, x) = map(int, stdin.readline().strip().split())
	if t == 1:
		if a[x - 1]:
			a[x - 1] = 0
			ones -= 1
		else:
			a[x - 1] = 1
			ones += 1
	elif ones >= x:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
count_0 = 0
count_1 = 0
arr = list(map(int, input().split()))
for i in arr:
	if i == 1:
		count_1 = count_1 + 1
	elif i == 0:
		count_0 = count_0 + 1
for d in range(q):
	(q1, x) = map(int, input().split())
	if q1 == 1:
		if arr[x - 1] == 1:
			count_1 = count_1 - 1
			count_0 = count_0 + 1
		elif arr[x - 1] == 0:
			count_0 = count_0 - 1
			count_1 = count_1 + 1
		arr[x - 1] = 1 - arr[x - 1]
	elif q1 == 2:
		if x > count_1:
			print(0)
		elif x <= count_1:
			print(1)


import sys

def debug(*args):
	print(*args, file=sys.stderr)

def read_str():
	return sys.stdin.readline().strip()

def read_int():
	return int(sys.stdin.readline().strip())

def read_ints():
	return map(int, sys.stdin.readline().strip().split())

def read_str_split():
	return list(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def Main():
	(n, q) = read_ints()
	a = read_int_list()
	cnt_one = a.count(1)
	for _ in range(q):
		(t, x) = read_ints()
		if t == 1:
			if a[~-x] == 1:
				a[~-x] = 0
				cnt_one -= 1
			else:
				a[~-x] = 1
				cnt_one += 1
		elif cnt_one >= x:
			print(1)
		else:
			print(0)
Main()


import sys
input = sys.stdin.readline

def print(x, end='\n'):
	sys.stdout.write(str(x) + end)

def get_int():
	return int(input())

def get_list_ints():
	return list(map(int, input().split()))

def get_char_list():
	s = input()
	return list(s[:len(s) - 1])

def get_tuple_ints():
	return tuple(map(int, input().split()))

def print_iterable(p):
	print(' '.join(map(str, p)))

def main():
	(n, q) = get_tuple_ints()
	a = get_list_ints()
	k = a.count(1)
	for _ in range(q):
		(t, x) = get_tuple_ints()
		if t == 1:
			if a[x - 1] == 1:
				a[x - 1] = 0
				k -= 1
				continue
			else:
				a[x - 1] = 1
				k += 1
				continue
		else:
			c = a
			if x <= k:
				print(1)
			else:
				print(0)
			continue
main()


import sys
input = sys.stdin.readline
(N, Q) = map(int, input().split())
A = list(map(int, input().split()))
ones = sum((v == 1 for v in A))
for _ in range(Q):
	(t, x) = map(int, input().split())
	if t == 1:
		x -= 1
		if A[x] == 0:
			ones += 1
		else:
			ones -= 1
		A[x] = 1 - A[x]
	else:
		print(1 if x <= ones else 0)


import sys
from collections import *
import math
import bisect

def input():
	return sys.stdin.readline()
(n, q) = map(int, input().split())
a = list(map(int, input().split()))
cnt = Counter(a)
for _ in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if a[x - 1] == 0:
			cnt[1] += 1
			cnt[0] -= 1
		else:
			cnt[1] -= 1
			cnt[0] += 1
		a[x - 1] = 1 - a[x - 1]
	elif x <= cnt[1]:
		print(1)
	else:
		print(0)


(n, m) = input().split(' ')
matriz = list(map(int, input().split(' ')))
maior = sum(matriz)
for i in range(int(m)):
	(t, x) = input().split(' ')
	x = int(x)
	if t == '2':
		if x <= maior:
			print(1)
		else:
			print(0)
	elif matriz[x - 1] == 0:
		matriz[x - 1] = 1
		maior += 1
	else:
		matriz[x - 1] = 0
		maior -= 1


from math import *
from bisect import *
from collections import *
from random import *
from decimal import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = 1
while t:
	t -= 1
	(n, q) = ma()
	a = lis()
	c = a.count(1)
	for i in range(q):
		(x, y) = ma()
		if x == 1:
			if a[y - 1] == 1:
				c -= 1
				a[y - 1] = 0
			else:
				c += 1
				a[y - 1] = 1
		elif y > c:
			print(0)
		else:
			print(1)


import sys

def f2(n, q, x, a, b):
	c = x.count(1)
	d = x.count(0)
	for i in range(q):
		if a[i] == 1:
			if x[b[i] - 1] == 1:
				c = c - 1
				d = d + 1
				x[b[i] - 1] = 0
				continue
			if x[b[i] - 1] == 0:
				c = c + 1
				d = d - 1
				x[b[i] - 1] = 1
				continue
		if a[i] == 2:
			if b[i] > c:
				print(0)
			if b[i] <= c:
				print(1)
input = sys.stdin.read()
data = list(map(int, input.split()))
n = data[0]
q = data[1]
x = data[2:2 + n]
l = 0
a = []
b = []
for i in range(q):
	a.append(data[2 + n + l])
	b.append(data[2 + n + l + 1])
	l = l + 2
f2(n, q, x, a, b)


(n, q) = input().split()
lista = input().split()
uns = lista.count('1')
for i in range(int(q)):
	(t, xk) = input().split()
	if t == '1':
		if lista[int(xk) - 1] == '1':
			lista[int(xk) - 1] = '0'
			uns -= 1
		else:
			lista[int(xk) - 1] = '1'
			uns += 1
	elif int(xk) <= uns:
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
c = l.count(1)
for _ in range(q):
	(t, x) = map(int, input().split())
	if t == 1:
		if l[x - 1] == 1:
			l[x - 1] = 0
			c -= 1
		else:
			l[x - 1] = 1
			c += 1
	elif x <= c:
		print(1)
	else:
		print(0)


import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, q) = mi()
a = li()
one = a.count(1)
for _ in range(q):
	(t, x) = mi()
	if t == 1:
		x -= 1
		if a[x] == 0:
			one += 1
		else:
			one -= 1
		a[x] = 1 - a[x]
	elif one >= x:
		print(1)
	else:
		print(0)


def main():
	(n, q) = map(int, input().split())
	arr = list(map(int, input().split()))
	cnt = {0: 0, 1: 0}
	for val in arr:
		cnt[val] = cnt[val] + 1
	result = []
	for _ in range(q):
		(t, x) = map(int, input().split())
		if t == 1:
			arr[x - 1] = 1 - arr[x - 1]
			if arr[x - 1] == 0:
				cnt[0] += 1
				cnt[1] -= 1
			else:
				cnt[1] += 1
				cnt[0] -= 1
		elif x > cnt[1]:
			result.append('0')
		else:
			result.append('1')
	print('\n'.join(result))
main()


(n, q) = map(int, input().split())
li = list(map(int, input().split()))
z = li.count(0)
o = n - z
for i in range(q):
	(t, k) = map(int, input().split())
	if t == 1:
		if li[k - 1] == 0:
			o += 1
			z -= 1
			li[k - 1] = 1
		else:
			li[k - 1] = 0
			o -= 1
			z += 1
	elif t == 2:
		if k <= o:
			print(1)
		else:
			print(0)


import math
import sys

def inpu():
	return sys.stdin.readline().strip()
(n, q) = map(int, inpu().split())
a = list(map(int, inpu().split()))
d = False
os = a.count(1)
for i in range(q):
	(t, b) = map(int, inpu().split())
	if t == 1:
		if a[b - 1] == 1:
			a[b - 1] = 0
			os -= 1
		else:
			a[b - 1] = 1
			os += 1
	elif b <= os:
		print(1)
	else:
		print(0)


R = lambda : map(int, input().split())
(n, q) = R()
a = [0, *R()]
r = sum(a)
while q:
	q -= 1
	(t, x) = R()
	if t < 2:
		a[x] ^= 1
		r += 2 * a[x] - 1
	else:
		print(+(x <= r))


(n, q) = map(int, input().split())
l = list(map(int, input().split()))
s = 0
for k in l:
	if k == 1:
		s = s + 1
for j in range(q):
	(az, m) = map(int, input().split())
	if az == 1:
		if l[m - 1] == 1:
			s = s - 1
			l[m - 1] = 0
		else:
			l[m - 1] = 1
			s = s + 1
	elif m > s:
		print(0)
	else:
		print(1)


import typing
import sys
import math
import collections
import bisect
import itertools
import decimal
import heapq
inf = 10 ** 20
mod = 10 ** 9 + 7

def ni():
	return int(sys.stdin.buffer.readline())

def ns():
	return map(int, sys.stdin.buffer.readline().split())

def na():
	return list(map(int, sys.stdin.buffer.readline().split()))

def na1():
	return list(map(lambda x: int(x) - 1, sys.stdin.buffer.readline().split()))

def nall():
	return list(map(int, sys.stdin.buffer.read().split()))

def flush():
	return sys.stdout.flush()

def nic():
	return int(sys.stdin.readline())

def nsc():
	return map(int, sys.stdin.readline().split())

def nac():
	return list(map(int, sys.stdin.readline().split()))

def na1c():
	return list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))

def main():
	(n, q) = ns()
	a = na()
	one = a.count(1)
	for _ in range(q):
		(x, y) = ns()
		if x == 1:
			y -= 1
			a[y] ^= 1
			if a[y] == 1:
				one += 1
			else:
				one -= 1
		else:
			print(1 if one >= y else 0)
main()


(n, q) = map(int, input().split())
data = list(map(int, input().split()))
c = data.count(1)
for _ in range(q):
	(t, a) = map(int, input().split())
	if t == 1:
		data[a - 1] = 1 - data[a - 1]
		if data[a - 1] == 1:
			c += 1
		else:
			c -= 1
	elif t == 2:
		if a > c:
			print(0)
		else:
			print(1)


(n, q) = map(int, input().split())
arr = list(map(int, input().split()))
count_1 = arr.count(1)
for i in range(q):
	(x, y) = map(int, input().split())
	if x == 1:
		if arr[y - 1] == 1:
			arr[y - 1] = 0
			count_1 = count_1 - 1
		else:
			arr[y - 1] = 1
			count_1 = count_1 + 1
	elif count_1 >= y:
		print(1)
	else:
		print(0)


import math
from collections import defaultdict, Counter
from itertools import permutations
from decimal import Decimal, localcontext
from collections import defaultdict
ii = lambda : int(input())
li = lambda : list(map(int, input().split()))

def main():
	(n, q) = li()
	l = li()
	cc = l.count(1)
	for _ in range(q):
		(t, a) = li()
		if t == 2:
			if a <= cc:
				print(1)
			else:
				print(0)
		else:
			l[a - 1] = 1 - l[a - 1]
			if l[a - 1] == 1:
				cc += 1
			else:
				cc -= 1
import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, q) = map(int, input().split())
(*a,) = map(str, input().split())
c = ''.join(a).count('1')
for i in range(q):
	(x, y) = map(str, input().split())
	if x == '1':
		if a[int(y) - 1] == '1':
			c -= 1
			a[int(y) - 1] = '0'
		else:
			c += 1
			a[int(y) - 1] = '1'
	elif c >= int(y):
		print(1)
	else:
		print(0)


(n, q) = map(int, input().split())
a_list = list(map(int, input().split()))
zeros = a_list.count(0)
ones = a_list.count(1)
for _ in range(q):
	(t, x_or_k) = map(int, input().split())
	if t == 1:
		if a_list[x_or_k - 1] == 0:
			zeros -= 1
			ones += 1
		else:
			zeros += 1
			ones -= 1
		a_list[x_or_k - 1] = 1 - a_list[x_or_k - 1]
	else:
		print(1 if x_or_k <= ones else 0)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	(n, q) = get_ints()
	arr = get_list()
	one = sum(arr)
	zero = n - one
	while q:
		(x, y) = get_ints()
		if x == 1:
			t = arr[y - 1]
			if t == 0:
				zero -= 1
				one += 1
			else:
				one -= 1
				zero += 1
			arr[y - 1] = 1 - t
		elif y <= one:
			get_print_int(1)
		else:
			get_print_int(0)
		q -= 1
solve()


def asss(i):
	global c1
	li[i] = 1 - li[i]
	if li[i] == 1:
		c1 += 1
	else:
		c1 -= 1

def pri(i):
	if i <= c1:
		print(1)
	else:
		print(0)
(tcs, q) = list(map(int, input().split()))
li = list(map(int, input().split()))
c1 = li.count(1)
for tc in range(q):
	(mode, pos) = map(int, input().split())
	if mode == 1:
		asss(pos - 1)
	else:
		pri(pos)


from sys import stderr

def dbp(*args, **kwargs):
	print(*args, file=stderr, **kwargs)

def get_int_list():
	return [int(x) for x in input().strip().split()]

def do_thing():
	(n, q) = get_int_list()
	pcount = 0
	alist = []
	for c in input().strip().split():
		v = 0 if c == '0' else 1
		alist.append(v)
		pcount += v
	outl = []
	for _ in range(q):
		(qt, v) = get_int_list()
		if qt == 1:
			if alist[v - 1] == 0:
				pcount += 1
			else:
				pcount -= 1
			alist[v - 1] = 1 - alist[v - 1]
		else:
			assert qt == 2
			out = 1 if v - 1 < pcount else 0
			outl.append(str(out))
	return '\n'.join([str(x) for x in outl])

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
print(do_thing())


def solve():
	(n, q) = map(int, input().split())
	a = list(map(int, input().split()))
	ones = a.count(1)
	for i in range(q):
		(op, indx) = map(int, input().split())
		if op == 1:
			if a[indx - 1] == 1:
				ones -= 1
			else:
				ones += 1
			a[indx - 1] = 1 - a[indx - 1]
		elif ones < indx:
			print(0)
		else:
			print(1)
t = 1
for _ in range(t):
	solve()


import sys
from collections import Counter

def solve(a, q):
	n = len(a)
	cnt = Counter(a)
	ones = cnt.get(1, 0)
	zeros = cnt.get(0, 0)
	assert ones + zeros == n
	for _ in range(q):
		(t, k) = list(map(int, sys.stdin.readline().rstrip().split(' ')))
		k -= 1
		if t == 1:
			if a[k] == 1:
				ones -= 1
				zeros += 1
			else:
				ones += 1
				zeros -= 1
			a[k] = 1 - a[k]
		else:
			x = 1 if k < ones else 0
			print(x)
(_, q) = list(map(int, sys.stdin.readline().rstrip().split(' ')))
a = list(map(int, sys.stdin.readline().rstrip().split(' ')))
solve(a, q)


from math import sqrt
import operator
import sys
inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def check_seq(n, seq):
	return res

def main():
	(n, q) = read_list_of_ints()
	seq = read_list_of_ints()
	ones_cnt = sum(seq)
	for _ in range(q):
		(t, x) = read_list_of_ints()
		if t == 1:
			if seq[x - 1] == 1:
				seq[x - 1] = 0
				ones_cnt -= 1
			else:
				seq[x - 1] = 1
				ones_cnt += 1
		if t == 2:
			if x <= ones_cnt:
				print('1')
			else:
				print('0')
main()


import sys
import math
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor, log
from bisect import bisect_right, bisect_left, bisect
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)
T = 1
N = 10000
for _ in range(T):
	(n, q) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	d = {0: 0, 1: 0}
	for i in a:
		d[i] += 1
	for _ in range(q):
		(c, x) = list(map(int, stdin.readline().rstrip().split()))
		if c == 1:
			d[a[x - 1]] -= 1
			a[x - 1] = 1 - a[x - 1]
			d[a[x - 1]] += 1
		elif d[1] >= x:
			print(1)
		else:
			print(0)