fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. set<int> s;
  6. int q;
  7. while(cin >> q){
  8. if(q == 1){
  9. int x;
  10. cin >> x;
  11. s.insert(x);
  12. }
  13. else if(q == 2){
  14. int x;
  15. cin >> x;
  16. if(s.find(x) != s.end()){
  17. s.erase(x);
  18. }
  19. }
  20. else if(q == 3){
  21. if(s.empty() == 1){
  22. cout << "empty\n";
  23.  
  24. }
  25. else cout << *s.begin() << "\n";
  26. }
  27. else if(q == 4){
  28. if(s.empty() == 1){
  29. cout << "empty\n";
  30.  
  31. }
  32. else cout << *s.rbegin() << "\n";
  33. }
  34. else if(q == 5){
  35. int x;
  36. cin >> x;
  37. if(s.empty() == 1){
  38. cout << "empty\n";
  39.  
  40. }
  41. else{
  42. auto it = s.upper_bound(x);
  43. if(it == s.end()){
  44. cout << "no\n";
  45. }
  46. else{
  47. cout << *it << "\n";
  48. }
  49. }
  50. }
  51. else if(q == 6){
  52. int x;
  53. cin >> x;
  54. if(s.empty() == 1){
  55. cout << "empty\n";
  56.  
  57. }
  58. else {
  59. auto it = s.lower_bound(x);
  60. if(it == s.end()){
  61. cout << "no\n";
  62. }
  63. else{
  64. cout << *it << "\n";
  65. }
  66. }
  67.  
  68. }
  69. else if(q == 7){
  70. int x;
  71. cin >> x;
  72. if(s.empty() == 1){
  73. cout << "empty\n";
  74.  
  75. }
  76. else {
  77. auto it = s.lower_bound(x);
  78. it--;
  79. int y = *it;
  80. if(s.count(y) && y < x){
  81. cout << y << "\n";
  82. }
  83. else{
  84. cout << "no\n";
  85. }
  86.  
  87. }
  88.  
  89. }
  90. else if(q == 8){
  91. int x;
  92. cin >> x;
  93. if(s.empty() == 1){
  94. cout << "empty\n";
  95.  
  96. }
  97. else {
  98. auto it = s.upper_bound(x);
  99. it--;
  100. int y = *it;
  101. if(s.count(y) && y <= x){
  102. cout << y << "\n";
  103. }
  104. else{
  105. cout << "no\n";
  106. }
  107. }
  108.  
  109. }
  110. else{
  111. break;
  112. }
  113.  
  114. }
  115.  
  116.  
  117. return 0;
  118. }
  119.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty