fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32.  
  33. // ---------- set ----------
  34.  
  35.  
  36. // Strict Ceil (> x)
  37. int sCeil(set<int> &s, int x){
  38.  
  39. auto it = s.upper_bound(x);
  40.  
  41. if(it == s.end()) return -1;
  42.  
  43. return *it;
  44. }
  45.  
  46. // Strict Floor (< x)
  47. int sFloor(set<int> &s, int x){
  48.  
  49. auto it = s.lower_bound(x);
  50.  
  51. if(it == s.begin()) return -1;
  52. --it;
  53.  
  54. return *it;
  55. }
  56.  
  57. // Loose Ceil (>= x)
  58. int ceil(set<int> &s, int x){
  59.  
  60. auto it = s.lower_bound(x);
  61.  
  62. if(it == s.end()) return -1;
  63. return *it;
  64. }
  65.  
  66. // Loose Floor (<= x)
  67. int floor(set<int> &s, int x){
  68.  
  69. auto it = s.upper_bound(x);
  70.  
  71. if(it == s.begin()) return -1;
  72. --it;
  73.  
  74. return *it;
  75. }
  76.  
  77.  
  78.  
  79. void solve() {
  80.  
  81. set<int> st = {2, 5, 3, 6, 10, 22};
  82.  
  83. cout << "Set => ";
  84. for(auto& s : st) cout << s << " "; cout << endl;
  85.  
  86. int x = 6;
  87.  
  88. cout << "Smallest(" << x << ") : " << *st.begin() << endl;
  89.  
  90. cout << "Largest(" << x << ") : " << *st.rbegin() << endl;
  91.  
  92. cout << "Strict Ceil (>" << x << ") : " << sCeil(st, x) << endl;
  93.  
  94. cout << "Strict Floor (<" << x << ") : " << sFloor(st, x) << endl;
  95.  
  96. cout << "Loose Ceil (>=" << x << ") : " << ceil(st, x) << endl;
  97.  
  98. cout << "Loose Floor(<=" << x << ") : " << floor(st, x) << endl;
  99.  
  100.  
  101. }
  102.  
  103.  
  104.  
  105.  
  106. int32_t main() {
  107. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  108.  
  109. int t = 1;
  110. // cin >> t;
  111. while (t--) {
  112. solve();
  113. }
  114.  
  115. return 0;
  116. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Set => 2 3 5 6 10 22 
Smallest(6)        : 2
Largest(6)         : 22
Strict Ceil (>6)   : 10
Strict Floor (<6)  : 5
Loose Ceil (>=6)   : 6
Loose Floor(<=6)   : 6