Advertisement
TAHMID37

Tamzid_boss

Oct 30th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. /*  TAHMID RAHMAN
  2.     DAMIAN FOREVER
  3.      MATH LOVER
  4.     NEVER GIVE UP
  5. */
  6. #include<bits/stdc++.h>
  7. using namespace std;
  8. #define pi acos(-1.0)
  9. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  10. #define ll long long
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. #define in insert
  15. #define mp make_pair
  16. #define GCD(a,b) __gcd(a,b);
  17. #define endl "\n"
  18. #define FRU freopen("out.txt","w",stdout)
  19. #define FRO freopen("in.txt","r",stdin)
  20. #define INFLL 9223372036854775807
  21. #define debug 0
  22. #define MAXN   100001
  23. #define ar array
  24. #define lb lower_bound
  25. #define ub upper_bound
  26. const int mxN=2e5;
  27. const int MOD=1e9+7;
  28. template<typename ForwardIterator, typename T>
  29. ForwardIterator first_less_than (ForwardIterator first, ForwardIterator last, T value)
  30. {auto it = std::lower_bound (first, last, value);
  31. return (it == first ? last : --it);}
  32. bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)
  33. {
  34.     return (a.second < b.second);
  35. }
  36. #define debugxx(v) {for(auto x:v){cout<<x.fi<<" "<<x.se<<endl;}cout<<endl;}
  37. #define debugx(v){for(auto y:v) {cout<<y<<" ";}cout<<endl;}
  38. //Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
  39.  
  40. ll n,m;
  41.  
  42. ll a[10000][10000];
  43.  
  44. bool bs(ll k)
  45. {
  46.     ll i=0,j=0;
  47.  
  48.     while(i<n)
  49.     {
  50.         if(a[i][0]<=k&&a[i][m-1]>=k)
  51.         {
  52.             ll l=0,h=m-1;
  53.             ll mid;
  54.  
  55.             while(l<=h)
  56.             {
  57.                 mid=(l+h)/2;
  58.  
  59.                 if(a[i][mid]==k)
  60.                     return true;
  61.  
  62.                 if(a[i][mid]<k)
  63.                 {
  64.                     l=mid+1;
  65.                 }
  66.                 else
  67.                     h=mid-1;
  68.             }
  69.         }
  70.         else
  71.             i++;
  72.  
  73.  
  74.     }
  75.  
  76.     return false;
  77.  
  78.  
  79. }
  80.  
  81. int main()
  82. {
  83.     fastio;
  84.     ll k,i,j;
  85.     cin>>n>>m>>k;
  86.  
  87.     for(i=0;i<n;i++)
  88.     {
  89.         for(j=0;j<m;j++)
  90.         {
  91.             cin>>a[i][j];
  92.         }
  93.     }
  94.  
  95.  
  96.     if(bs(k))
  97.         cout<<"True"<<endl;
  98.     else
  99.         cout<<"False"<<endl;
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement