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;
- typedef unsigned long long ull;
- #define testcase int t; cin>>t; while (t--)
- #define REP(i, n) for(int i=0; i<(int)(n); i++)
- #define REP1(i,a,b) for(int i=a; i<=(int)(b); i++
- #define sc(a) scanf("%lld",&a)
- #define sc2(a,b) scanf("%lld %lld",&a,&b)
- #define pb push_back
- #define reversed(s) reverse(s.begin(), s.end())
- #define asort(s) sort(s.begin(), s.end())
- #define dsort(s) sort(s.begin(), s.end(),greater<ll>())
- #define gtl(x) getline(cin, (x))
- #define PI acos(-1)
- #define CLR(x, y) memset(x, y, sizeof(x))
- #define Precision(a) cout << fixed << setprecision(a)
- #define FasterIo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #define endl "\n"
- template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
- template <typename T> T Pow(T B,T P){ if(P==0) return 1; if(P&1) return B*Pow(B,P-1); else return Sqr(Pow(B,P/2));}
- template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
- template <typename T> T Gcd(T a,T b){if(a<0)return Gcd(-a,b);if(b<0)return Gcd(a,-b);return (b==0)?a:Gcd(b,a%b);}
- template <typename T> T Lcm(T a,T b) {if(a<0)return Lcm(-a,b);if(b<0)return Lcm(a,-b);return a*(b/Gcd(a,b));}
- ll binary_search(ll a[], ll L, ll R, ll num)
- {
- // l=0, l=n-1
- while(L<=R)
- {
- ll Mid = L+(R-L)/2;
- if(a[Mid]==num)
- {
- return Mid;
- }
- else if(a[Mid]<num)
- {
- L = Mid+1;
- }
- else
- {
- R = Mid-1;
- }
- }
- return -1;
- }
- int main()
- {
- #ifdef FLAME
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("ouut.txt", "w", stdout);
- #endif
- int n, i;
- cin >> n;
- ll a[n+5];
- for(int i=0; i<n; i++)
- {
- cin >> a[i];
- }
- int q;
- cin >> q;
- for(int i=0; i<q; i++)
- {
- int Num;
- cin >> Num;
- int idx = binary_search(a, 0, n-1, Num);
- if(idx == -1) {
- cout << "X X" << endl;
- continue;
- }
- ll temp = idx;
- int flag = 0;
- while(temp >= 0) {
- if(a[temp] < Num) {
- cout << a[temp] << " ";
- flag = 1;
- break;
- }
- temp--;
- }
- if(flag == 0) {
- cout << "X ";
- }
- temp = idx;
- flag = 0;
- while(temp <= n-1) {
- if(a[temp] > Num) {
- cout << a[temp];
- flag = 1;
- break;
- }
- temp++;
- }
- if(flag == 0) {
- cout << "X";
- }
- cout << endl;
- }
- #ifdef FLAME
- fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement