eolymp
bolt
Try our new interface for solving problems
Problems

Binary search - 1

published at 2/14/24, 6:28:28 am

include<bits/stdc++.h>

using namespace std; int main(){ int n,q; int x; cin>>n>>q; int a[n]; for(int i=0;i<n;i++){ cin>>a[i];

}
while(q--){
     cin>>x;
    auto up=upper_bound(a, a+n, x);
    auto lo=lower_bound(a, a+n, x);
     cout<<up-lo<<endl;
}

}