Advertisement
Korotkodul

Задача №111728. Левый и правый двоичный поиск

Nov 15th, 2021
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <set>
  5. #include <string>
  6. #include <algorithm>
  7. using namespace std;
  8. using ll = long long;
  9. void co(vector <int> v){
  10. for (auto x: v) cout<<x<<'\n';
  11. cout<<'\n';
  12. }
  13.  
  14. int main()
  15. {
  16. int n, m;
  17. cin>>n>>m;
  18. vector <int> A(n);
  19. for (int &x: A) cin>>x;
  20. vector <int> B(m);
  21. for (int &x: B) cin>>x;
  22. for (int x: B){
  23. auto L = lower_bound(A.begin(), A.end(), x);
  24. int l = L - A.begin();
  25. auto R = upper_bound(A.begin(), A.end(), x);
  26. int r = R - A.begin();
  27. if (R - L == 0){
  28. cout<<0<<'\n';
  29. }
  30. else cout<<l + 1<<' '<<r<<'\n';
  31. }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement