fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9. vector<int> A;
  10. for (int i = 0; i < n; ++i){
  11. int a;
  12. cin >> a;
  13. A.push_back(a);
  14. }
  15.  
  16. int m;
  17. cin >> m;
  18. vector<int> B;
  19. for (int i = 0; i < m; ++i){
  20. int a;
  21. cin >> a;
  22. int x = 0;
  23. auto lower = lower_bound(A.begin(), A.end(), a);
  24. auto upper = upper_bound(A.begin(), A.end(), a);
  25. int count = upper - lower;
  26. cout << count << endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5292KB
stdin
14
1 1 3 4 5 5 6 8 8 13 14 17 19 20
3
1 2 3
stdout
2
0
1