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