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;
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(nullptr);
- LL i,j,n,x,y,z;
- cin>>n;
- LL a[100005];
- for(i=0;i<n;i++) cin>>a[i];
- sort(a,a+n);
- cin>>x;
- for(i=0;i<x;i++)
- {
- cin>>y;
- LL low=0,high=n-1,mid;
- while(low<=high)
- {
- mid=(low+high)/2;
- //cout<<"mid = "<<mid<<"low = "<<low<<"high = "<<high<<endl;
- //cout<<y<<endl;
- if(y>=a[mid-1] && y<=a[mid]) break;
- else if(y>=a[mid]) low=mid+1;
- else high=mid-1;
- }
- if(y==a[mid]) cout<<mid+1<<"\n";
- else if(y<a[mid] && y>=a[0]) cout<<mid<<"\n";
- else if(y<a[0]) cout<<0<<"\n";
- else if(y>a[n-1]) cout<<n<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement