# tìm kiếp nhị phân
def tknp(arr, x):
t, p = 0, len(arr)
while t < p:
g = (t + p) // 2
if arr[g] < x:
t = g + 1
else:
p = g
return t
n = int(input())
a = list(map(int,input().split()))
c = sorted(a) # sắp xếp bé -> lớn
q = int(input())
for i in range(q):
m = int(input())
print(tknp(c, m))
# tìm kiếp nhị phân
def tknp(a, x):
t, p = 0, len(a)
while t <= p:
g = (t + p) // 2
if a[g] == x:
return "YES"
elif a[g] < x:
t = g + 1
else :
p = g - 1
return "NO"
n , k = map(int,input().split())
a = list(map(int,input().split()))
x = list(map(int,input().split()))
for i in x :
print(tknp(a,i))
def tknp(arr,x):
t,p = 0,len(arr)
while t < p :
g = (t+p)//2
if arr[g] < x :
t = g + 1
else :
p = g
return t
n = int(input())
a = list(map(int,input().split()))
c = sorted(a)
for i in a :
print(tknp(c,i),end=" ")
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up