fork download
  1. /*
  2.   Keep Watching (^.^)
  3.   ~~~~ hmanh2007 ~~~~
  4. ████████████████
  5. █░░░░░░██░░░░░░█
  6. █░░▄▀░░██░░▄▀░░█
  7. █░░▄▀░░██░░▄▀░░█
  8. █░░▄▀░░██░░▄▀░░█
  9. █░░▄▀░░░░░░▄▀░░█
  10. █░░▄▀▄▀▄▀▄▀▄▀░░█
  11. █░░▄▀░░░░░░▄▀░░█
  12. █░░▄▀░░██░░▄▀░░█
  13. █░░▄▀░░██░░▄▀░░█
  14. █░░▄▀░░██░░▄▀░░█
  15. █░░░░░░██░░░░░░█
  16. ████████████████
  17. */
  18. #include <bits/stdc++.h>
  19. using namespace std;
  20. typedef long long ll;
  21. const ll mod = 65536;
  22. const ll NH = 250005;
  23. bool multitest = 1;
  24. multiset<ll> s1, s2;
  25. string type;
  26. ll n, x;
  27. void solve()
  28. {
  29. cin >> type;
  30. if (type == "MEDIAN")
  31. {
  32. if (n == 0)
  33. {
  34. cout << "0\n";
  35. return;
  36. }
  37. if (n & 1) cout << *s2.begin() << "\n";
  38. else cout << (*s1.rbegin() + *s2.begin()) / double(2) << "\n";
  39. }
  40. if (type == "IN")
  41. {
  42. n++;
  43. cin >> x;
  44. if (s1.size() > 0 && x <= *s1.rbegin()) s1.insert(x); else s2.insert(x);
  45. while (s1.size() > n / 2)
  46. {
  47. s2.insert(*s1.rbegin());
  48. s1.erase(--s1.end());
  49. }
  50. while (s2.size() > n - n / 2)
  51. {
  52. s1.insert(*s2.begin());
  53. s2.erase(s2.begin());
  54. }
  55. }
  56. if (type == "OUT")
  57. {
  58. cin >> x;
  59. n--;
  60. if (s1.size() > 0 && x <= *s1.rbegin()) s1.erase(s1.find(x));
  61. else s2.erase(s2.find(x));
  62. while (s1.size() > n / 2)
  63. {
  64. s2.insert(*s1.rbegin());
  65. s1.erase(--s1.end());
  66. }
  67. while (s2.size() > n - n / 2)
  68. {
  69. s1.insert(*s2.begin());
  70. s2.erase(s2.begin());
  71. }
  72. }
  73. }
  74. int main()
  75. {
  76. ios_base::sync_with_stdio(false);
  77. cin.tie(NULL); cout.tie(NULL);
  78. if (fopen("Code.inp", "r"))
  79. {
  80. freopen("Code.inp", "r", stdin);
  81. freopen("Code.out", "w", stdout);
  82. }
  83. int T;
  84. if (multitest) cin >> T;
  85. else T = 1;
  86. for (int i = 1; i <= T; i++) solve();
  87. return 0;
  88. }
  89. /*
  90.   ~~~~ ROSÉ ~~~~
  91. ⢀⣀⣤⣤⣤⣴⠶⠦⢤⣄⣤⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  92. ⠘⣧⠀⢄⠀⠀⠀⠰⡀⠀⠉⠈⠙⢦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  93. ⠀⠹⣆⠀⠙⠢⣀⠀⢳⠀⠀⢸⠀⠈⠛⢷⠴⠲⠤⣄⣀⡤⠤⢤⣀⣀⠀⠀⢀⣠⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  94. ⠀⠀⣿⠀⠀⠀⠈⠳⢾⡀⠀⠀⡇⢀⡴⠋⠀⣠⣞⣉⣀⠀⢀⣀⣀⣉⠙⢶⡋⠀⠀⠙⢶⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  95. ⠀⠀⠘⢧⡀⠐⠢⠤⠼⠛⢶⣼⢷⣿⠞⢩⠟⠋⣁⡴⠛⣉⣉⠤⢤⣉⡉⠓⠿⣟⠲⢄⡀⠙⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  96. ⠀⠀⠀⠈⣿⡆⠀⠀⠀⢀⣀⣿⠟⠁⣰⠃⠀⡴⢋⡴⠊⣁⣀⣀⠀⠀⠙⢿⠲⢾⡆⠀⠈⠙⢺⡷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀
  97. ⠀⠀⠀⠀⠈⠻⢦⣈⠉⣩⣿⡁⠀⡞⢻⠀⢸⠃⢸⣅⡞⠁⠀⠸⣝⣦⠀⠈⡇⠈⣷⠀⠀⠀⢠⡇⠀⣹⡆⠀⠀⠀⠀⠀⠀⠀
  98. ⠀⠀⠀⠀⠀⠀⣴⠛⠋⠁⠀⠳⡄⠻⡌⠳⣼⣤⡏⠙⢧⡀⢀⣀⡼⢈⣧⣀⡿⢡⠟⠀⠆⠀⢨⣧⣠⡟⠀⠀⠀⠀⠀⠀⠀⠀
  99. ⠀⠀⠀⠀⠀⠀⠹⡆⠀⠀⠀⠀⠻⣄⠈⢻⣦⣍⣳⣤⣀⣙⣶⣶⡯⠭⠤⠤⠾⣿⣶⡾⠀⣠⠟⠹⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀
  100. ⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⢇⠀⠀⢹⣦⡀⠙⢦⡉⠙⠓⠶⠦⠤⠤⠴⠒⠛⢩⡿⠋⣀⡼⠁⠀⢠⣧⣄⣀⠀⠀⠀⠀⠀⠀⠀
  101. ⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠈⠳⣄⡀⣧⠉⠳⢤⡙⢦⡀⠀⠀⠀⠀⠀⣠⠞⣉⣠⠾⠛⠁⣀⣴⠟⣀⠀⠉⢿⣆⠀⠀⠀⠀⠀
  102. ⠀⠀⠀⠀⠀⠀⠀⠘⢷⣄⠀⠀⠀⠙⠻⠦⣄⣤⣽⠶⠿⠦⠴⠖⠒⠛⠛⣉⣁⣠⣤⡶⠛⢩⡟⠉⠀⠀⠀⠀⠉⠳⣄⠀⠀⠀
  103. ⠀⠀⠀⠀⠀⠀⠀⠀⣀⣨⣿⣶⣤⣄⡀⠀⠀⠉⠙⠛⠿⠿⣿⣛⠛⠋⠉⠉⠁⠀⣼⠀⠀⣼⣧⣀⣠⠴⠒⠊⠉⠀⢼⡇⠀⠀
  104. ⠀⠀⠀⠀⠀⣀⡴⠟⠉⠀⡀⠀⠸⡏⠉⠙⠒⠶⠤⠤⠤⠴⣾⠙⣧⠀⠀⠀⠀⢠⡇⠀⢰⡏⢻⡉⠙⠒⠢⠤⣀⡀⠀⠹⣆⠀
  105. ⠀⠀⠀⣠⠞⠉⠀⣀⠀⠀⠈⠉⢓⣿⣄⠀⠀⠀⠀⠀⠀⠀⢻⣄⠈⢧⡀⠀⢀⣾⣤⢶⡏⠀⠀⠳⡄⠀⠀⠀⠀⠀⢀⣀⡽⠆
  106. ⠀⠀⢨⡟⠁⠀⠀⠀⠈⠙⣲⡶⢿⠁⢻⢦⣀⠀⠀⠀⠀⠀⠀⠈⠳⣜⡇⣠⠟⠁⠀⠠⣿⣤⣴⡤⣤⣤⡶⠖⠚⠛⠉⠁⠀⠀
  107. ⠀⢠⡟⠀⠠⠤⠤⣤⡴⢾⠉⠀⢸⠀⠸⠀⣹⠗⠦⣤⣀⣀⣀⣀⣠⡼⣿⠉⠑⠦⣀⠀⢹⡄⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  108. ⠀⢺⡇⠀⠀⢀⠔⠋⠀⡏⠀⠀⠄⢀⡀⣴⠏⠀⠀⠀⢹⡍⠉⠀⠀⡰⢻⣆⠀⠀⠀⠁⠀⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  109. ⠀⣼⠀⢀⠖⠁⠀⠀⠸⠀⢀⣄⣠⠞⠟⠁⠀⠀⠀⠀⠘⣷⡆⠀⡰⠁⠈⡏⠙⢦⡀⠀⣰⠿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  110. ⠀⣿⣀⣀⣤⠤⣶⣤⠴⠚⠉⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡔⠁⠀⠀⢻⠀⠀⠘⢂⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  111. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⡀⠀⠸⡄⠀⣰⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  112. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣆⠈⠀⣰⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  113. ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢷⣼⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
  114. */
  115.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty