#include<cstdio> #include<cstring> #include<algorithm> usingnamespacestd; constint maxn = 10020; int tot, bit[maxn]; voidupdate(int i, int x){ for (; i <= tot; i += i & -i) bit[i] += x; }
intfindK(int k){ int ans = 0; for (int x = (1 << 16); x; x >>= 1) { if (ans + x < tot && bit[ans + x] < k) { k -= bit[ans += x]; } } return ans; } char Q[maxn]; int a[maxn], b[maxn], n; voidinit(){ n = 0; memset(bit, 0, sizeof(bit)); }
intmain(){ int qn, ti = 0; while (scanf("%d", &qn) != EOF) { init(); ++ti; printf("Case #%d:\n", ti); for (int i = 0; i < qn; i++) { char s[10]; scanf("%s", s); Q[i] = s[0]; if (Q[i] == 'i') { scanf("%d", &a[n]); b[n] = a[n]; n++; } } sort(b, b + n); tot = n; for (int i = 0; i < n; i++) a[i] = lower_bound(b, b + n, a[i]) - b + 1; int ql = 0, qr = 0; for (int i = 0; i < qn; i++) { if (Q[i] == 'i') { update(a[qr++], 1); } elseif (Q[i] == 'o') { update(a[ql++], -1); } else { printf("%d\n", b[findK((qr - ql + 2)/ 2)]); } } } }