Skip to content

Instantly share code, notes, and snippets.

@modos
Created April 26, 2023 11:19
Show Gist options
  • Save modos/370c5d8915b1979f1630e10fd0d6d93f to your computer and use it in GitHub Desktop.
Save modos/370c5d8915b1979f1630e10fd0d6d93f to your computer and use it in GitHub Desktop.
جست‌وجو در دنباله ۲
n, q = map(int, input().split())
a = list(map(int, input().split()))
# M = a[1]
# for i in range(2, n):
# M = max(M, a[i])
M = max(a)
cnt = [0 for i in range(M + 1)]
for i in range(0, n):
cnt[a[i]] += 1
ps = [0 for i in range(M)]
for i in range(1, M):
ps[i] = ps[i - 1] + cnt[i]
for i in range(q):
x = int(input())
if x > M:
print(n)
else:
print(ps[x-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment