Advertisement
Falak_Ahmed_Shakib

binary upper_bound

Nov 9th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. /*
  2. , \ / ,
  3. / \ )\__/( / \
  4. / \ (_\ /_) / \
  5. ____/_____\__\@ @/___/_____\____
  6. | |\../| |
  7. | \VV/ |
  8. | ------___------- |
  9. |__________Chuta Dragon___________|
  10. | /\ / \\ \ /\ |
  11. | / V )) V \ |
  12. |/ ` // ' \|
  13. ` V '
  14. */
  15. #include<bits/stdc++.h>
  16. using namespace std;
  17. typedef long long ll;
  18. #define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
  19. #define fi first
  20. #define se second
  21. #define pb push_back
  22. #define eb emplace_back
  23. void input(ll ara[],ll n)
  24. {
  25. for(ll i=0; i<n; i++)
  26. cin>>ara[i];
  27. }
  28.  
  29. #define eb emplace_back
  30. int main()
  31. {
  32. fastread();
  33.  
  34. ll n,a,q,i;
  35.  
  36. cin>>n;
  37.  
  38. vector<ll>v;
  39.  
  40.  
  41.  
  42. for(i=0; i<n; i++)
  43. {
  44. cin>>a;
  45.  
  46. v.pb(a);
  47. }
  48.  
  49. // v.pb(*min_element(v.begin(),v.end()));
  50.  
  51. sort(v.begin(),v.end());
  52.  
  53. cin>>q;
  54.  
  55. while(q--)
  56. {
  57. cin>>a;
  58.  
  59. ll ans=upper_bound(v.begin(),v.end(),a)-v.begin();
  60.  
  61. cout<<ans<<endl;
  62. }
  63.  
  64. }
  65.  
  66. //////////////////////////////////////////////////////////////////////////////////////////////////////
  67. // //
  68. // //
  69. // _____________ //
  70. // ++++++++++ ___------------------\\\\ //
  71. // +++`+``+`+`++++ ///`````````````````````````````\\\ //
  72. // ++`+`+``+++`++++ /////```````````````````````````````````\\ //
  73. // +++`++`+`+``+++/////`````````````````````````````````````````\\ //
  74. // +++`++`+``+///```````````|```````````````````````````````````\\ //
  75. // ____++++/++++/`````````````/````````|````````|```````````````````\\ //
  76. // / / / | //``````````````|````````|```````|````````|````````````\\ //
  77. // / / / | ///````````/```````|```````||```````|````````|``````\```````\\ //
  78. // | / / |///`````````|``````/````````|````````|````````|```````|```````\\ //
  79. // |/ | |//``|```````|``````|````````|`````````|```````|```````|````````\\ //
  80. // /\___|__//`|``|```````|` | ``:|````````|:```````|```````|```|`````| //
  81. // / / /``|``|``````|/ | :| ```:|```````|```````|``++````++ //
  82. // / / //```|``|``````| | |: :| ```|```````|```++``++`\ //
  83. // | / /````|``|``````/ _.::::. | | | ````|```|`++`\`| //
  84. // | / |````|``|`````| ` | ``|```++``++`| //
  85. // | / |````|``|`````| : |``++````++| //
  86. // | / /````|``|`````| _.-:::. |..`|``.`|.| //
  87. // |/ /`````|``|`````| ` |```|````|`| //
  88. // /| |`````|``|`````| :' .|```|````|.| //
  89. // / | |`````|``|`````| /|-|``|````|`| //
  90. // / | |`````|```\````| / ||```|````|``\ //
  91. // / | |`````|````|```|:: /_| ||```|````|``| //
  92. // |`````|````|```|:|:. `.._ .\___/:|```|````|``| //
  93. // |`````\````|```|:|::- ``:::.... -:|:|:::|```|````|``| //
  94. // |``````|```|```|:|::`|. .:::|:|:::|```|````|``| //
  95. // \`````|```|```|:|::/|--. .`:|:::|:|:::/```|````|``| //
  96. // |````|```|```\:|:|:|----- _..-:|:|:|:::|:|::|````|````|`/ //
  97. // |````|```|````\|:|:|-------.____.....------|/::|:::|:|::|````|````|`| //
  98. // |````|```|\````\:|/\___________ ________/\--\:::|:|::|````/````|`| //
  99. // |````\```| \```|:/-------------\ /----------\``\::|:|::|```/`````|`| //
  100. // |`````|``| \``|/---------------\/------------\_________|```|`````|`| //
  101. // //
  102. //////////////////////////////////////////////////////////////////////////////////////////////////////
  103. // //
  104. // Created by Aeren //
  105. // //
  106. //////////////////////////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement