fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define ll long long
  4. using namespace std;
  5.  
  6. int q, t, x;
  7. multiset <int> s;
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  11. cin >> q;
  12. while(q--)
  13. {
  14. cin >> t >> x;
  15. if(t == 1)
  16. s.insert(x);
  17. else if(t == 2)
  18. {
  19. if(s.find(x) != s.end())
  20. s.erase(s.find(x));
  21. }
  22. else if(t == 3)
  23. {
  24. auto it = s.find(x);
  25. if(it != s.end())
  26. cout << "YES ";
  27. else
  28. cout << "NO ";
  29.  
  30. auto k = s.lower_bound(x);
  31. if(k == s.begin())
  32. cout << -1 << endl;
  33. else
  34. {
  35. --k;
  36. cout << *k << endl;
  37. }
  38. }
  39. else if (t == 4)
  40. {
  41. auto it = s.find(x);
  42. if(it != s.end())
  43. cout << "YES ";
  44. else
  45. cout << "NO ";
  46.  
  47. auto k = s.upper_bound(x);
  48. if(k == s.end())
  49. cout << -1 << endl;
  50. else
  51. cout << *k << endl;
  52. }
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty