Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- ll binary_searc(ll arr[],ll n,ll a)
- {
- ll l=0,r=n-1;
- ll res=-1;
- while(l<=r)
- {
- ll mid=(l+r)/2;
- if(arr[mid]==a)
- {
- res=mid;
- r=mid-1;
- }
- if(arr[mid]<a)
- {
- l=mid+1;
- }
- else r=mid-1;
- }
- return res;
- }
- int main()
- {
- ll n,q;
- cin>>n>>q;
- ll arr[n];
- for(ll i=0;i<n;i++)
- {
- scanf("%lld",&arr[i]);
- }
- while(q--)
- {
- ll a;
- scanf("%lld",&a);
- printf("%d\n",binary_searc(arr,n,a));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement