fork download
  1. import java.util.*;
  2. import java.io.*;
  3. class Sol{
  4.  
  5.  
  6. public static void main(String args[]) throws Exception{
  7. int n=Integer.valueOf(br.readLine());
  8. int arr[]=new int[n];
  9. HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
  10. String ss=br.readLine();
  11. String[] s=ss.split(" ");
  12. for(int i=0;i<n;i++){
  13. //System.out.println(s[i]);
  14. arr[i]=Integer.valueOf(s[i]);
  15. hm.put(arr[i],hm.getOrDefault(arr[i],0)+1);
  16. }
  17. //System.out.println(hm);
  18.  
  19. int que=Integer.valueOf(br.readLine());
  20.  
  21. while(que--!=0){
  22. int rst=0;
  23. int x=Integer.valueOf(br.readLine().trim());
  24. //System.out.println(x);
  25. if(hm.get(x) != null)
  26. {
  27. rst=hm.get(x);
  28. }
  29. wr.write(rst+"\n");
  30.  
  31. }
  32.  
  33. wr.flush();
  34.  
  35. }
  36. }
  37.  
Success #stdin #stdout 0.09s 50136KB
stdin
9
-6 10 -1 20 -1 15 5 -1 15 
5
-1
10
8
15
20
stdout
3
1
0
2
1