Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- ll lowerBound(ll arr[],ll n,ll x)
- {
- ll l=0 , r=n-1;
- ll ans=-1;
- while(l<=r)
- {
- ll mid = l+(r-l)/2;
- if(arr[mid]>=x)
- {
- ans=mid;
- r=mid-1;
- }
- else
- l=mid+1;
- }
- return ans;
- }
- ll upperBound(ll arr[],ll n,ll x)
- {
- ll l=0,r=n-1;
- ll ans=-1;
- while(l<=r)
- {
- ll mid = l+(r-l)/2;
- if(arr[mid]<=x)
- {
- ans=mid;
- l=mid+1;
- }
- else
- r=mid-1;
- }
- return ans+1;
- }
- int main()
- {
- ll ch,query;
- cin >> ch;
- ll chimp[ch];
- for(int i=0;i<ch;i++)
- cin >> chimp[i];
- cin >> query;
- ll luchu[query];
- for(int i=0;i<query;i++)
- cin >> luchu[i];
- ll s,t;
- for(ll i=0;i<query;i++)
- {
- s = lowerBound(chimp,ch,luchu[i]);
- t = upperBound(chimp,ch,luchu[i]);
- if(s==0)
- cout << "X ";
- else if(s==-1)
- cout << chimp[ch-1] << " ";
- else
- cout << chimp[s-1] << " ";
- if(t==ch)
- cout << "X" << endl;
- else
- cout << chimp[t] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement