Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Enter your code here. Read input from STDIN. Print output to STDOUT
- t=int(input())
- for _ in range(t):
- n=int(input())
- shelf=list(map(int,input().split()))
- pa=int(input())
- pages=list(map(int,input().split()))
- li=[]
- se=set(shelf)
- se=list(se)
- se = sorted(se, reverse = True) # update 3
- l=len(se)
- for i in pages:
- low,hi=0,l
- if i<se[-1]: # update 1
- li.append(l+1)
- elif i>se[0]: # update 2
- li.append(1)
- else:
- while low<hi:
- mid=(low+hi)//2
- if (se[mid-1]>i and se[mid]<i) or se[mid]==i:
- li.append(mid+1)
- break
- elif se[mid] < i:
- hi=mid
- elif se[mid] > i:
- low=mid+1
- print(*li)
Advertisement
Add Comment
Please, Sign In to add comment