SHARE
TWEET

Untitled

a guest Jan 24th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n,q;
  5. long long arr[1000001],dato;
  6. int in,fi,mid;
  7.  
  8. int main (){
  9.   cin.tie(0);
  10.   ios_base::sync_with_stdio(0);
  11.   cin>>n>>q;
  12.   for(int i=0; i<n; i++){
  13.     cin>>arr[i];
  14.   }
  15.   for(int i=0; i<q; i++){
  16.     cin>>dato;
  17.     in=0;
  18.     fi=n-1;
  19.     while(1){
  20.       mid=(in+fi)/2;
  21.       /**if(in>fi){
  22.         cout<<"DATO NO ENCONTRADO";
  23.         break;
  24.       }*/
  25.       if(arr[mid]==dato){
  26.         cout<<mid<<" ";
  27.         break;
  28.       }
  29.       if(arr[mid]>dato){
  30.         fi=mid-1;
  31.       }else if(arr[mid]<dato){
  32.         in=mid+1;
  33.       }
  34.     }
  35.  
  36.   }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top