fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, q;
  7. cin >> n >> q;
  8.  
  9. vector<int> freq(n + 1, 0);
  10.  
  11. // Read array and count frequency
  12. for (int i = 0; i < n; i++) {
  13. int x;
  14. cin >> x;
  15. freq[x]++;
  16. }
  17.  
  18. // Process queries
  19. while (q--) {
  20. int x;
  21. cin >> x;
  22. cout << freq[x] << endl;
  23. }
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5292KB
stdin
5 1
1 2 3 3 5
3
stdout
2