Advertisement
Galebickosikasa

Untitled

Dec 20th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
  2. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
  3. // #pragma comment(linker, "/stack:200000000"]
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <unordered_set>
  10. #include <unordered_map>
  11. #include <set>
  12. #include <map>
  13. #include <queue>
  14. #include <deque>
  15. #include <bitset>
  16. #include <stack>
  17. #include <random>
  18. #include <fstream>
  19. #include <sstream>
  20. #include <chrono>
  21.  
  22. #define fi first
  23. #define se second
  24. #define pb push_back
  25. #define ll long long
  26. #define ld long double
  27. #define hm unordered_map
  28. #define pii pair<int, int>
  29. #define sz(a) (int)a.size()
  30. #define all(a) a.begin(), a.end()
  31. #define cinv(v) for (auto& x: v) cin >> x
  32. #define fr(i, n) for (int i = 0; i < n; ++i)
  33. #define fl(i, l, n) for (int i = l; i < n; ++i)
  34.  
  35. // #define int ll
  36.  
  37. template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
  38. template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
  39.  
  40. using namespace std;
  41.  
  42. #ifdef LOCAL
  43. #define dbg(x) cerr << #x << " : " << x << '\n'
  44. const int maxn = 20;
  45. #else
  46. #define dbg(x)
  47. const int maxn = 2e5 + 20;
  48. #endif
  49.  
  50. //tg: @galebickosikasa
  51.  
  52. ostream& operator << (ostream& out, const pii& v) {
  53. out << v.fi << ", " << v.se;
  54. return out;
  55. }
  56.  
  57. template<typename T> ostream& operator << (ostream& out, const vector<T>& v) {
  58. for (auto& x: v) out << x << " ";
  59. return out;
  60. }
  61.  
  62. istream& operator >> (istream& in, pii& a) {
  63. in >> a.fi >> a.se;
  64. return in;
  65. }
  66.  
  67. const ll inf = (ll) 2e9;
  68. const ld pi = asin (1) * 2;
  69. const ld eps = 1e-8;
  70. const ll mod = (ll)1e9 + 7;
  71. const ll ns = 97;
  72.  
  73. mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
  74.  
  75. struct tree {
  76. vector<int> t;
  77. int size = 0, capacity;
  78.  
  79. tree (int n) {
  80. while ((1<<size) < n) ++size;
  81. ++size;
  82. size = (1<<size);
  83. capacity = (size>>1);
  84. t = vector<int> (size);
  85. }
  86.  
  87. int get (int cur, int k) {
  88. if (cur * 2 >= size) return cur - capacity;
  89. if (t[cur * 2] >= k) return get (cur * 2, k);
  90. return get (cur * 2 + 1, k - t[cur * 2]);
  91. }
  92.  
  93. void add (int i, int x) {
  94. i += capacity;
  95. t[i] += x;
  96. i >>= 1;
  97. while (i) {
  98. t[i] = t[i * 2] + t[i * 2 + 1];
  99. i >>= 1;
  100. }
  101. }
  102. };
  103.  
  104. signed main () {
  105. ios_base::sync_with_stdio(false);
  106. cin.tie(nullptr);
  107. cout.tie(nullptr);
  108. int n;
  109. cin >> n;
  110. vector<pii> kek;
  111. fr (i, n) {
  112. string t;
  113. int x = 0;
  114. cin >> t;
  115. if (t == "add") {
  116. cin >> x;
  117. kek.pb ({0, x});
  118. }
  119. if (t == "min") kek.pb ({1, x});
  120. if (t == "max") kek.pb ({2, x});
  121. if (t == "mid") kek.pb ({3, x});
  122. }
  123. vector<int> tmp;
  124. for (auto& x: kek) tmp.pb (x.se);
  125. sort (all (tmp));
  126. tmp.resize (unique (all (tmp)) - tmp.begin ());
  127. for (auto& x: kek) x.se = (int)(lower_bound (all (tmp), x.se) - tmp.begin ());
  128. int m = sz (tmp);
  129. tree goo (m);
  130. int cnt = 0;
  131. for (auto& t: kek) {
  132. if (t.fi == 0) {
  133. goo.add (t.se, 1);
  134. ++cnt;
  135. } else if (t.fi == 1) {
  136. int x = goo.get (1, 1);
  137. cout << tmp[x] << '\n';
  138. goo.add (x, -1);
  139. --cnt;
  140. } else if (t.fi == 2) {
  141. int x = goo.get (1, cnt);
  142. cout << tmp[x] << '\n';
  143. goo.add (x, -1);
  144. --cnt;
  145. } else {
  146. int x = goo.get (1, (cnt + 1) / 2);
  147. cout << tmp[x] << '\n';
  148. goo.add (x, -1);
  149. --cnt;
  150. }
  151. }
  152.  
  153.  
  154.  
  155.  
  156.  
  157. }
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement