Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5. vector<int> vect(100000);
  6. int main()
  7. {
  8. int a, b, z;
  9. cin >> a;
  10. for(int i = 0; i< a; i++) cin >> vect[i];
  11. sort(vect.begin(), vect.begin() + a);
  12. cin >> b;
  13. for (int i = 0; i< b; i++) {
  14. int l = -1, r = a, l1 = -1, r1 = a;
  15. cin >> z;
  16. while (r - l > 1) {
  17. int x = (r + l) / 2;
  18. if (vect[x] >= z)
  19. r = x;
  20. else
  21. l = x;
  22. }
  23. while (r1 - l1 > 1) {
  24. int x = (r1 + l1) / 2;
  25. if (vect[x] > z)
  26. r1 = x;
  27. else
  28. l1 = x;
  29. }
  30. //cout << r << ' ' << r1 << endl;
  31. if (r < a && vect[r] == z) {
  32. cout << l1 - r+ 1;
  33. }
  34. else {
  35. cout << 0;
  36. }
  37. cout << ' ';
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement