【思路】Map键值对
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n =  sc.nextInt();
            Map<Integer, Integer> map = new TreeMap<>();
            for(int i=0; i<n; i++){
                int k =sc.nextInt();
                if(map.containsKey(k)){
                    map.put(k ,map.get(k)+1);
                     
                }else{
                    map.put(k ,1);
                }
            }
            int num = sc.nextInt();
            for(int i=0; i<num; i++){
                int key = sc.nextInt();
                if(map.containsKey(key)){
                    System.out.print(map.get(key));
                }else{
                    System.out.print(0);
                }
                if( i != num-1){
                    System.out.print(" ");
                }
            }
        }
         
    }
}