Advertisement
aurko96

Codeforce- 706B

Dec 12th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. using namespace std;
  4. int main()
  5. {
  6.     ios_base::sync_with_stdio(0);
  7.     cin.tie(nullptr);
  8.     LL i,j,n,x,y,z;
  9.     cin>>n;
  10.     LL a[100005];
  11.     for(i=0;i<n;i++) cin>>a[i];
  12.     sort(a,a+n);
  13.     cin>>x;
  14.     for(i=0;i<x;i++)
  15.     {
  16.         cin>>y;
  17.         LL low=0,high=n-1,mid;
  18.         while(low<=high)
  19.         {
  20.             mid=(low+high)/2;
  21.             //cout<<"mid = "<<mid<<"low = "<<low<<"high = "<<high<<endl;
  22.             //cout<<y<<endl;
  23.             if(y>=a[mid-1] && y<=a[mid]) break;
  24.             else if(y>=a[mid]) low=mid+1;
  25.             else high=mid-1;
  26.         }
  27.         if(y==a[mid]) cout<<mid+1<<"\n";
  28.         else if(y<a[mid] && y>=a[0]) cout<<mid<<"\n";
  29.         else if(y<a[0]) cout<<0<<"\n";
  30.         else if(y>a[n-1]) cout<<n<<"\n";
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement