Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- int main() {
- std::cin.sync_with_stdio(false);
- std::cout.sync_with_stdio(false);
- int n;
- std::cin >> n;
- std::vector<int> v;
- for (int i = 0; i < n; i++) {
- int num;
- std::cin >> num;
- v.push_back(num);
- }
- int n2;
- std::cin >> n2;
- for (int i = 0; i < n2; i++) {
- int number_to_search;
- std::cin >> number_to_search;
- std::vector<int>::iterator it_low = std::lower_bound(v.begin(), v.end(), number_to_search);
- std::vector<int>::iterator it_up = std::upper_bound(v.begin(), v.end(), number_to_search);
- if (std::binary_search(v.begin(), v.end(), number_to_search)) {
- std::cout << "Yes " << it_low - v.begin() + 1 << std::endl;
- }
- else {
- std::cout << "No " << it_up - v.begin() + 1 << std::endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment