fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n, q;
  6. cin>>n;
  7.  
  8. vector<int> arr(n);
  9. for (int i=0; i<n; i++){
  10. cin>>arr[i];
  11. }
  12.  
  13. cin>>q;
  14. vector<int> query(q);
  15. for (int i=0; i<q; i++){
  16. cin>>query[i];
  17. }
  18.  
  19. int maxele = INT_MIN;
  20. for (int i=0; i<n; i++){
  21. maxele = max(maxele, arr[i]);
  22. }
  23.  
  24. // cout<<maxele<<endl;
  25.  
  26. vector<int>hash(maxele+1, 0);
  27. // cout<<hash[maxele]<<endl;
  28.  
  29. for (int i=0; i<n; i++){
  30. hash[arr[i]]++;
  31. }
  32.  
  33. for (int i=0; i<q; i++){
  34. if (query[i] > maxele)
  35. cout<<query[i]<<" -> "<<0<<endl;
  36. else cout<<query[i]<<" -> "<<hash[query[i]]<<endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0.01s 5320KB
stdin
10
1 2 3 4 3 2 1 45 5 5
4
5 2 45 60
stdout
5 -> 2
2 -> 2
45 -> 1
60 -> 0