Advertisement
Mohammad_Dipu_Sultan

Playboychimp.w

Jul 14th, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5.  
  6. #define testcase int t; cin>>t; while (t--)
  7. #define REP(i, n) for(int i=0; i<(int)(n); i++)
  8. #define REP1(i,a,b) for(int i=a; i<=(int)(b); i++
  9. #define sc(a) scanf("%lld",&a)
  10. #define sc2(a,b) scanf("%lld %lld",&a,&b)
  11. #define pb push_back
  12. #define reversed(s) reverse(s.begin(), s.end())
  13. #define asort(s) sort(s.begin(), s.end())
  14. #define dsort(s) sort(s.begin(), s.end(),greater<ll>())
  15. #define gtl(x) getline(cin, (x))
  16. #define PI acos(-1)
  17. #define CLR(x, y) memset(x, y, sizeof(x))
  18. #define Precision(a) cout << fixed << setprecision(a)
  19. #define FasterIo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  20. #define endl "\n"
  21.  
  22. template <typename T> T Sqr(T x) { T n = x * x ; return n ;}
  23. 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));}
  24. template <typename T> T Abs(T a) {if(a<0)return -a;else return a;}
  25. 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);}
  26. 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));}
  27. ll binary_search(ll a[], ll L, ll R, ll num)
  28. {
  29. // l=0, l=n-1
  30. while(L<=R)
  31. {
  32. ll Mid = L+(R-L)/2;
  33. if(a[Mid]==num)
  34. {
  35. return Mid;
  36. }
  37. else if(a[Mid]<num)
  38. {
  39. L = Mid+1;
  40. }
  41. else
  42. {
  43. R = Mid-1;
  44. }
  45. }
  46. return -1;
  47. }
  48.  
  49. int main()
  50. {
  51. #ifdef FLAME
  52. clock_t tStart = clock();
  53. freopen("input.txt", "r", stdin);
  54. freopen("ouut.txt", "w", stdout);
  55. #endif
  56. int n, i;
  57. cin >> n;
  58. ll a[n+5];
  59.  
  60. for(int i=0; i<n; i++)
  61. {
  62. cin >> a[i];
  63. }
  64. int q;
  65. cin >> q;
  66. for(int i=0; i<q; i++)
  67. {
  68. int Num;
  69. cin >> Num;
  70. int idx = binary_search(a, 0, n-1, Num);
  71. if(idx == -1) {
  72. cout << "X X" << endl;
  73. continue;
  74. }
  75.  
  76. ll temp = idx;
  77. int flag = 0;
  78. while(temp >= 0) {
  79. if(a[temp] < Num) {
  80. cout << a[temp] << " ";
  81. flag = 1;
  82. break;
  83. }
  84. temp--;
  85. }
  86. if(flag == 0) {
  87. cout << "X ";
  88. }
  89.  
  90. temp = idx;
  91. flag = 0;
  92. while(temp <= n-1) {
  93. if(a[temp] > Num) {
  94. cout << a[temp];
  95. flag = 1;
  96. break;
  97. }
  98. temp++;
  99. }
  100. if(flag == 0) {
  101. cout << "X";
  102. }
  103. cout << endl;
  104. }
  105. #ifdef FLAME
  106. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  107. #endif
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement