- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Main. */
- Scanner sc=new Scanner(System.in);
- int t=sc.nextInt();
- while(t--!=0){
- int n=sc.nextInt();
- int arr[]=new int[n];
- for(int i=0;i<arr.length;i++){
- arr[i]=sc.nextInt();
- }
- int m=sc.nextInt();
- int p[]=new int[m];
- for(int i=0;i<m;i++){
- p[i]=sc.nextInt();
- }
- HashMap<Integer,Integer> map=new HashMap<>();
- for(int i=0;i<n;i++){
- map.put(arr[i],map.getOrDefault(arr[i],0)+1);
- }
- ArrayList<Integer> l=new ArrayList<>(map.keySet());
- for(int i=0;i<p.length;i++){
- int key=p[i];
- int low=0;
- int high=l.size()-1;
- int ans=-1;
- while(low<=high){
- int mid=low+(high-low)/2;
- if(l.get(mid)>key){
- ans=mid;
- low=mid+1;
- }else{
- high=mid-1;
- }
- }
- System.out.println(ans+2);
- }
- }
- }
- }
[text] 1
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: