Lower Bound-STL

Sort by

recency

|

434 Discussions

|

  • + 1 comment

    Hey guys..C++ solution

    int main() {

    long long n; cin>>n; vectora(n); for(long long i=0; i>a[i];

    long long q; cin>>q; for(int i=0; i>x;

    auto it=lower_bound(a.begin(),a.end(),x);
    long long index=it - a.begin();
    
    if(it!=a.end() && *it==x)
    {
        cout<<"Yes"<<" "<<index+1<<endl;
    }
    else 
    {
      cout<<"No"<<" "<<index+1<<endl;
    }
    

    }

    }
    
    • + 0 comments

      Do you give me thanks??

  • + 0 comments

    c++14

        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n =0;
        int x =0;
        vector<int>vek;
        cin>>n;
        while (n > 0) {
            cin>>x;
            vek.push_back(x);
            n--;
        }
        int q=0;
        cin>>q;
        while (q > 0) {
            int y =0;
            vector<int>::iterator it;
            cin>>y;
            it = lower_bound(vek.begin(),vek.end(), y);
            if (*it!=y) {
                cout<<"No "<<(it-vek.begin()+1)<<'\n';
            }else
            {cout<<"Yes "<<(it-vek.begin()+1)<<'\n';}
            q--;
        }
    
  • + 0 comments

    I want to use this css in website getseedsrightheredotcom for better function,is it possible

  • + 0 comments

    My C++ code 😎😁

    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    
    bool isHereElement(const std::vector<int>& arr, const int el, int* index) {
        auto it = std::lower_bound(arr.begin(), arr.end(), el);
        if (it != arr.end() && *it == el) {
            *index = std::distance(arr.begin(), it);
            return true;
        }
        return false;
    }
    
    int main() {
        int nbrInt = 0;
        std::cin >> nbrInt;
        std::vector<int> array(nbrInt, 0);
    
        for (int i = 0; i < nbrInt; i++) {
            std::cin >> array[i];
        }
        std::sort(array.begin(), array.end());
    
        int queries = 0;
        std::cin >> queries;
        std::vector<int> queriesArray(queries, 0);
    
        for (int i = 0; i < queries; i++) {
            std::cin >> queriesArray[i];
        }
    
        int index = 0;
        for (int i = 0; i < queriesArray.size(); i++) {
            if (isHereElement(array, queriesArray[i], &index)) {
                std::cout << "Yes " << index + 1 << std::endl;
            } else {
                auto indexLowerBound = std::lower_bound(array.begin(), array.end(), queriesArray[i]);
                std::cout << "No " << std::distance(array.begin(), indexLowerBound) + 1 << std::endl;
            }
        }
        return 0;
    }
    
  • + 0 comments

    I Dont know why everyone is confusing, the most simplest answer..

    int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int n ; cin >> n; vectornums(n); for(int i = 0;i> nums[i]; }

    int q;
    cin >> q;
    while(q--)
    {
        int target;
        cin >> target;
        auto it = lower_bound(nums.begin(),nums.end(),target);
        if(*it == target)
        {
            cout << "Yes " <<  it-nums.begin()+1 << endl;
        }
        else {
            cout << "No " << it-nums.begin()+1<<endl;
        }
    }
    return 0;
    

    }