fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. long long n,q;
  11. cin>>n>>q;
  12.  
  13. long long arr[n];
  14. for(int i=0;i<n;i++){cin>>arr[i];}
  15.  
  16. sort(arr,arr+n);
  17.  
  18. while(q--){//5
  19. long long x;
  20. cin>>x;
  21.  
  22. long long start=0;
  23. long long endd=n-1;
  24. long long mid;
  25. bool found=false;
  26.  
  27. for(int i=0;i<n/2;i++){//4.5
  28. mid=(start+endd)/2;
  29. if(x==arr[mid]||x==arr[start]||x==arr[endd]){found=true;break;}
  30. else if(x>arr[mid]){start=mid+1;}
  31. else if(x<arr[mid]){endd=mid-1;}
  32. else{found=false;}
  33. }
  34. if(found){cout<<"found"<<endl;}
  35. else{cout<<"not found"<<endl;}
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
not found
not found