You are viewing a single comment's thread. Return to all comments →
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); for (int i = 0; i < n; ++i) { cin >> arr[i]; } int q; cin >> q; for (int i = 0; i < q; ++i) { int x; cin >> x; auto it = lower_bound(arr.begin(), arr.end(), x); if (*it == x) { cout << "Yes " << it - arr.begin() + 1 << endl; } else { cout << "No " << it - arr.begin() + 1 << endl; } } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Lower Bound-STL
You are viewing a single comment's thread. Return to all comments →